How do I find the ruby interpreter?

前端 未结 2 1135
盖世英雄少女心
盖世英雄少女心 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"
    
    0 讨论(0)
  • 2020-12-15 07:57

    To get the path of the currently running ruby interpreter:

    require 'rbconfig'
    RUBY_INTERPRETER_PATH = File.join(RbConfig::CONFIG["bindir"],
                                      RbConfig::CONFIG["RUBY_INSTALL_NAME"] +
                                      RbConfig::CONFIG["EXEEXT"])
    
    0 讨论(0)
提交回复
热议问题