module Monkey::Engine

Makes sure we always have RUBY_ENGINE, RUBY_ENGINE_VERSION and RUBY_DESCRIPTION TODO: Check IronRuby version detection.

Constants

REAL_RUBY_ENGINE
REAL_RUBY_ENGINE_VERSION
RUBY_DESCRIPTION
RUBY_ENGINE
RUBY_ENGINE_VERSION
RUBY_ENINGE

Public Class Methods

ironruby?() click to toggle source
# File lib/monkey/engine.rb, line 10
def ironruby?; RUBY_ENGINE == "ironruby"; end
jruby?() click to toggle source
# File lib/monkey/engine.rb, line 7
def jruby?;    RUBY_ENGINE == "jruby";    end
macruby?() click to toggle source
# File lib/monkey/engine.rb, line 11
def macruby?;  RUBY_ENGINE == "macruby";  end
maglev?() click to toggle source
# File lib/monkey/engine.rb, line 12
def maglev?;   RUBY_ENGINE == "maglev";   end
mri?() click to toggle source
# File lib/monkey/engine.rb, line 8
def mri?;      RUBY_ENGINE == "ruby";     end
rbx?() click to toggle source
# File lib/monkey/engine.rb, line 9
def rbx?;      RUBY_ENGINE == "rbx";      end
Also aliased as: rubinius?
ree?() click to toggle source
# File lib/monkey/engine.rb, line 16
def ree?
  !!(RUBY_DESCRIPTION =~ %rRuby Enterprise Edition/) || RUBY_ENGINE == "ree"
end
rubinius?() click to toggle source
Alias for: rbx?
ruby_core?() click to toggle source
# File lib/monkey/engine.rb, line 29
def ruby_core?
  maglev? or rubinius?
end
ruby_engine(engine = RUBY_ENGINE, pretty = true) click to toggle source
# File lib/monkey/engine.rb, line 84
def ruby_engine(engine = RUBY_ENGINE, pretty = true)
  return engine unless pretty
  case engine
  when "ruby"   then ree? ? "Ruby Enterprise Edition" : "Ruby"
  when "ree"    then "Ruby Enterprise Edition"
  when "rbx"    then "Rubinius"
  when "maglev" then "MagLev"
  else engine.capitalize.gsub("ruby", "Ruby")
  end
end
set_engine(engine, engine_version = nil) click to toggle source
# File lib/monkey/engine.rb, line 97
def self.set_engine(engine, engine_version = nil)
  Object.send :remove_const, "RUBY_ENGINE"
  Object.const_set "RUBY_ENGINE", engine
  if engine_version
    Object.send :remove_const, "RUBY_ENGINE_VERSION"
    Object.const_set "RUBY_ENGINE_VERSION", engine_version
  end
end
use_original_ruby_engine(&block) click to toggle source
# File lib/monkey/engine.rb, line 130
def use_original_ruby_engine(&block)
  if defined? ::OLD_RUBY_ENGINE then with_ruby_engine(::OLD_RUBY_ENGINE, ::OLD_RUBY_ENGINE_VERSION, &block)
  else with_ruby_engine(::RUBY_ENGINE, ::RUBY_ENGINE_VERSION, &block)
  end
end
use_real_ruby_engine(&block) click to toggle source
# File lib/monkey/engine.rb, line 124
def use_real_ruby_engine(&block)
  with_ruby_engine(::REAL_RUBY_ENGINE, ::REAL_RUBY_ENGINE_VERSION, &block)
end
with_ruby_engine(engine, engine_version) { || ... } click to toggle source
# File lib/monkey/engine.rb, line 106
def with_ruby_engine(engine, engine_version)
  engine_was, engine_version_was = ::RUBY_ENGINE, ::RUBY_ENGINE_VERSION
  unless defined? ::OLD_RUBY_ENGINE
    Object.const_set("OLD_RUBY_ENGINE", ::RUBY_ENGINE)
    Object.const_set("OLD_RUBY_ENGINE_VERSION", ::RUBY_ENGINE_VERSION)
  end
  Monkey::Engine.set_engine engine, engine_version
  if block_given?
    result = yield
    Monkey::Engine.set_engine engine_was, engine_version_was
    result
  else
    [engine_was, engine_version_was]
  end
end