I don't quite understand your question. You seem to be mixing two completely different abstraction levels: Ruby is a programming language, JRuby is a compiler for the Ruby programming language. The question whether your program is running in Ruby or in JRuby just plain doesn't make sense: when it's running in JRuby, it is running in Ruby, because JRuby is an implementation of Ruby.
It's the same as asking "how can I tell if I'm driving in a Ford vs. a car?"
If you want to know in what Ruby implementation you're running, then you can check the global RUBY_ENGINE
constant. It is supposed to universally and uniquely identify the engine you are running on, although it unfortunately fails for three reasons:
- on some engines, it doesn't tell you what engine it is running on, for example on YARV I would expect
RUBY_ENGINE
to be 'yarv'
, but it is actually 'ruby'
. So, it fails at the "identify" part.
- even worse: on MRI, it is also
'ruby'
, which means that not only does it not tell you what engine you are running on, but there also totally different engines that return the same value. IOW, it also fails at the "unique" part.
- and last but not least,
RUBY_ENGINE
is fairly new, so it is not yet supported by all engines, which means it fails at the "universal" part.
Still, for your purposes something like
if defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby'
should work fine.