问题
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