Detecting Which Ruby Interpreter is Running (JRuby, IronRuby)

I’m currently using a mix of Ruby interpreters for building a system. For instance, I use JRuby for Celerity, IronRuby for Windows Forms (on Mono) and MRI for other things.

To ensure I don’t mess things up, I came up with some tiny guards to get a clear message when I’m not using the interpreter I should be using. I’m sharing these here in case it’s useful to someone else.


# JRuby
abort $0 + " requires JRuby" unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" 

# IronRuby
abort($0 + " requires IronRuby") unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby" 

Note that RUBY_ENGINE doesn’t seem to be defined under MRI.

The comments system is brand new - don't be afraid to comment!