My employer has Ruby 1.8.7 in the /usr/bin/ruby, and allows the usage of Ruby 2.4 only via SCL (sofoware collections).
Which means that when I run ruby, I need to use (from the RH6 shell) scl enablde ruby-24 'ruby foo.rb'
when foo.rb
is the file name.
I want to enable the ruby call on the first execution line, i.e., instead of the Ruby code file looking like:
#!/usr/bin/ruby
puts "Hello world"
That the code will look
#!cmd
puts "Hello world"
Where the cmd is what calls via the scl
and run the Ruby 2.4 for the puts
command. I know that a wrapper file can be used. I want something in 1 file.
How about this:
#!/usr/bin/ruby
if RUBY_VERSION != "2.4.1"
exec "scl enable ruby-24; ruby __FILE__"
end
puts "Ruby Version: #{RUBY_VERSION}"