Module: Monkey::Engine
- Includes:
- Rubinius
- Defined in:
- lib/monkey/engine.rb
Overview
Makes sure we always have RUBY_ENGINE, RUBY_ENGINE_VERSION and RUBY_DESCRIPTION TODO: Check IronRuby version detection.
Class Method Summary collapse
- .ironruby? ⇒ Boolean
- .jruby? ⇒ Boolean
- .macruby? ⇒ Boolean
- .maglev? ⇒ Boolean
- .mri? ⇒ Boolean
- .rbx? ⇒ Boolean
- .ree? ⇒ Boolean
- .rubinius? ⇒ Boolean
- .ruby_core? ⇒ Boolean
- .ruby_engine(engine = RUBY_ENGINE, pretty = true) ⇒ Object
- .set_engine(engine, engine_version = nil) ⇒ Object
- .use_original_ruby_engine(&block) ⇒ Object
- .use_real_ruby_engine(&block) ⇒ Object
- .with_ruby_engine(engine, engine_version) ⇒ Object
Class Method Details
.ironruby? ⇒ Boolean
10 |
# File 'lib/monkey/engine.rb', line 10 def ironruby?; RUBY_ENGINE == "ironruby"; end |
.jruby? ⇒ Boolean
7 |
# File 'lib/monkey/engine.rb', line 7 def jruby?; RUBY_ENGINE == "jruby"; end |
.macruby? ⇒ Boolean
11 |
# File 'lib/monkey/engine.rb', line 11 def macruby?; RUBY_ENGINE == "macruby"; end |
.maglev? ⇒ Boolean
12 |
# File 'lib/monkey/engine.rb', line 12 def maglev?; RUBY_ENGINE == "maglev"; end |
.mri? ⇒ Boolean
8 |
# File 'lib/monkey/engine.rb', line 8 def mri?; RUBY_ENGINE == "ruby"; end |
.rbx? ⇒ Boolean
9 |
# File 'lib/monkey/engine.rb', line 9 def rbx?; RUBY_ENGINE == "rbx"; end |
.ree? ⇒ Boolean
16 17 18 |
# File 'lib/monkey/engine.rb', line 16 def ree? !!(RUBY_DESCRIPTION =~ /Ruby Enterprise Edition/) || RUBY_ENGINE == "ree" end |
.rubinius? ⇒ Boolean
14 |
# File 'lib/monkey/engine.rb', line 14 def rbx?; RUBY_ENGINE == "rbx"; end |
.ruby_core? ⇒ Boolean
29 30 31 |
# File 'lib/monkey/engine.rb', line 29 def ruby_core? maglev? or rubinius? end |
.ruby_engine(engine = RUBY_ENGINE, pretty = true) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# 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) ⇒ Object
97 98 99 100 101 102 103 104 |
# 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) ⇒ Object
130 131 132 133 134 |
# 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) ⇒ Object
124 125 126 |
# 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) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# 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 |