Rails:我的应用程序如何知道它是在MRI还是JRuby中运行? [英] Rails: How can my app tell if it is running in MRI or JRuby?

查看:62
本文介绍了Rails:我的应用程序如何知道它是在MRI还是JRuby中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个上一个问题中,我问如何告诉我的Gemfile是否服用与JRuby有关的宝石或与MRI有关的宝石.我得到的答案是在Gemfile中执行以下操作:

In a previous question, I asked how to tell my Gemfile whether to take the JRuby-relevant gems or the MRI-relevant gems. The answer I got was to do the following in the Gemfile:

platforms :jruby do
  gem "activerecord-jdbcsqlite3-adapter"
end

platforms :mri do
  gem "sqlite3"
end

很明显,Bundler中的platform()方法知道如何确定我正在运行MRI还是JRuby.我可以在程序中告诉我是否正在运行JRuby或MRI吗?

Obviously, the platforms() method in Bundler knows how to figure out if I'm running MRI or JRuby. Is there another way I can tell within my program if I am running JRuby or MRI?

推荐答案

您能这样区分两者吗?

case (RUBY_ENGINE)
when 'ruby'
  # ...
when 'jruby'
  # ...
end

如果需要,您可以编写一个方法为您提供jruby?方法:

You could write a method to give you a jruby? method if required:

def jruby?
  RUBY_ENGINE == 'jruby'
end

这篇关于Rails:我的应用程序如何知道它是在MRI还是JRuby中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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