简体   繁体   中英

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

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?

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

使用Ruby 2.2.3 Config::CONFIG给我NameError: uninitialized constant Config ,但是以下工作:

y RbConfig::CONFIG

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM