Feature #5445
openNeed RUBYOPT -r before ARGV -r
Description
Libraries given by -r options in RUBYOPT should be loaded before ones in direct command line arguments.
I use a custom load system for development that I have been using for years and it works very well for me. But Ruby has some edge cases that prevents it from being feature complete. One of these is the order in which RUBYOPT is applied vs. -r command line option.
My custom loader is too large to include here, so I will simply demonstrate the problem with simple sample code:
$ cat req.rb
p "Custom Require"
module Kernel
alias :require0 :require
def require(*a)
puts "Kernel#require"
p a
require0(*a)
end
class << self
alias :require0 :require
def require(*a)
puts "Kernel.require"
p a
require0(*a)
end
end
end
If we load this via RUBYOPT, the result is:
$ RUBYOPT=-r./req.rb ruby -rstringio -e0
Custom Require
But if we load via -r the result is:
$ ruby -r./req.rb -rstringio -e0
Custom Require
Kernel#require
["stringio"]
I would ask that the output of both invocations to be identical.
(Note, the -T option should still allow RUBYOPT to be omitted regardless.)