Rails: How can my app tell if it is running in MRI or JRuby?

淺唱寂寞╮ 提交于 2019-12-10 21:45:42

问题


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

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?


回答1:


Are you able to distinguish between the two like this:

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

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

def jruby?
  RUBY_ENGINE == 'jruby'
end



回答2:


With Ruby 2.2.3 Config::CONFIG gives me NameError: uninitialized constant Config, but the following works:

y RbConfig::CONFIG


来源:https://stackoverflow.com/questions/7822623/rails-how-can-my-app-tell-if-it-is-running-in-mri-or-jruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!