Bug #15738
closedRUBYOPT disables have precedence over the command line
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.
Updated by Eregon (Benoit Daloze) over 5 years ago
- Related to Bug #15736: r67361 Update to ruby/spec@e81b3cd - spec failures on MinGW ? added
Updated by shevegen (Robert A. Heiler) over 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.
Updated by nobu (Nobuyoshi Nakada) over 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]