Class: RubyEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/util/ruby_engine.rb

Overview

Sourced from rbjl.net/35-how-to-properly-check-for-your-ruby-interpreter-version-and-os Extracted from rubyzucker.info/ Copyright © 2010-2013 Jan Lelis <happycode.org> released under the MIT license

Class Method Summary collapse

Class Method Details

.cardinal?Boolean Also known as: parrot?, perl?

Returns:

  • (Boolean)


62
63
64
# File 'lib/util/ruby_engine.rb', line 62

def cardinal?
  RubyEngine.is? 'cardinal'
end

.interpreterObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/util/ruby_engine.rb', line 7

def interpreter
  case
  when RUBY_PLATFORM == 'parrot'
    'cardinal'
  when Object.constants.include?( :RUBY_ENGINE ) ||
       Object.constants.include?( 'RUBY_ENGINE'  )
    if RUBY_ENGINE == 'ruby'
      if RUBY_DESCRIPTION =~ /Enterprise/
        'ree'
      else
        'mri'
      end
    else
      RUBY_ENGINE.to_s # jruby, rbx, ironruby, macruby, etc.
    end
  else # probably 1.8
    'mri'
  end
end

.ironruby?Boolean Also known as: iron_ruby?

Returns:

  • (Boolean)


57
58
59
# File 'lib/util/ruby_engine.rb', line 57

def ironruby?
  RubyEngine.is? 'ironruby'
end

.is?(what) ⇒ Boolean Also known as: is

Returns:

  • (Boolean)


27
28
29
# File 'lib/util/ruby_engine.rb', line 27

def is?(what)
  what === interpreter
end

.jruby?Boolean Also known as: java?

Returns:

  • (Boolean)


42
43
44
# File 'lib/util/ruby_engine.rb', line 42

def jruby?
  RubyEngine.is? 'jruby'
end

.mri?Boolean Also known as: official_ruby?, ruby?

Returns:

  • (Boolean)


36
37
38
# File 'lib/util/ruby_engine.rb', line 36

def mri?
  RubyEngine.is? 'mri'
end

.ree?Boolean Also known as: enterprise?

Returns:

  • (Boolean)


52
53
54
# File 'lib/util/ruby_engine.rb', line 52

def ree?
  RubyEngine.is? 'ree'
end

.rubinius?Boolean Also known as: rbx?

Returns:

  • (Boolean)


47
48
49
# File 'lib/util/ruby_engine.rb', line 47

def rubinius?
  RubyEngine.is? 'rbx'
end

.to_sObject



32
33
34
# File 'lib/util/ruby_engine.rb', line 32

def to_s
  interpreter
end