我如何找到 ruby​​ 解释器? [英] How do I find the ruby interpreter?

查看:34
本文介绍了我如何找到 ruby​​ 解释器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ruby​​ 脚本中,如何获取 ruby​​ 解释器的路径?

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

示例脚本:

  #!/path/to/ruby
  puts `#{RUBY_INTERPRETER_PATH} -e "puts 'hi'"`
  #EOF

其中 RUBY_INTERPRETER_PATH 是寻找 /path/to/ruby 的神秘方式.

Where RUBY_INTERPRETER_PATH is a mythical way of finding /path/to/ruby.

不过,这只是一个例子.我意识到在这种情况下我可以将 /path/to/ruby 复制到脚本中,但我不想这样做.无论 #! 行说什么,我都希望它正确"工作.即使在 Windows 下运行.

This is just an example, though. I realize in this case that I could just copy /path/to/ruby into the script, but I don't want to do that. I want this to work "correctly" regardless of what the #! line says. Even if running under windows.

呸!

推荐答案

如今 (1.9+) 您可以像这样使用内置方法(应该与 Jruby 等一起使用):

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

RbConfig.ruby或者宝石.ruby

RbConfig.ruby or Gem.ruby

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

这篇关于我如何找到 ruby​​ 解释器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆