How do I find the ruby interpreter?

前端 未结 2 1144
盖世英雄少女心
盖世英雄少女心 2020-12-15 06:56

Inside a ruby script, how do I get the path to the ruby interpreter?

Example script:

  #!/path/to/ruby
  puts `#{RUBY_INTERPRETER_PATH} -e \"puts \'h         


        
2条回答
  •  盖世英雄少女心
    2020-12-15 07:56

    These days (1.9+) you can use built-in methods (which are supposed to work with Jruby, etc.) like this:

    RbConfig.ruby or Gem.ruby

    $ irb --simple-prompt
    >> RbConfig.ruby
    => "C:/installs/Ruby193/bin/ruby.exe"
    >> Gem.ruby
    => "C:/installs/Ruby193/bin/ruby.exe"
    

提交回复
热议问题