Project

General

Profile

Actions

Bug #15738

closed

RUBYOPT disables have precedence over the command line

Added by Eregon (Benoit Daloze) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
[ruby-core:92052]

Description

From #15736:

It seems unexpected that the command line argument doesn't override the RUBYOPT options:

$ RUBYOPT=--disable-gems ruby --enable=gems -e 'p defined?(Gem)'
nil

That seems a bug. I would expect the command line arguments always override RUBYOPT arguments.

This:

$ ruby --disable=gems --enable=gems -e 'p defined?(Gem)'     
"constant"
$ ruby --enable=gems --disable=gems -e 'p defined?(Gem)'
nil

works as expected.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #15736: r67361 Update to ruby/spec@e81b3cd - spec failures on MinGW ?ClosedActions
Actions #1

Updated by Eregon (Benoit Daloze) about 5 years ago

  • Related to Bug #15736: r67361 Update to ruby/spec@e81b3cd - spec failures on MinGW ? added

Updated by shevegen (Robert A. Heiler) about 5 years ago

I would expect the command line arguments always override RUBYOPT arguments.

I agree.

I do not know all specifics but it makes sense to me as to agree with what Benoit
wrote in regards to explicit commandline option(s) being able to overrule environment
variables.

Otherwise the situation would be that any environment variable would always have a higher
precedence over an explicit commandline instruction given by the user at hand, which would
mean that people would not be able to use various --flags to have higher priority over
environment variables. They would then, in this case, first have to disable the environment
variable, which I don't think makes a lot of sense.

In my largest gem I use the same approach to the behaviour Benoit described - I have code
that checks for some environment variables, but even if they exist, any explicit
commandline-instruction (in ruby passed through ARGV) would take precedence. The reasoning
goes like this "if the user specifically uses a certain option on the commandline, then
we have to trust that user to know what he/she is doing". Which I think is reasonable to
assume.

Actions #3

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r67388.


ruby.c: respect features by command line

  • ruby.c (process_options): feature options in command line
    arguments take precedence over options in RUBYOPT environment
    variable. [ruby-core:92052] [Bug #15738]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0