Module: HostOS::Interpreter

Defined in:
lib/host-os/interpreter.rb

Overview

This module allows to identify the used Ruby interpreter.

Besides here documented boolean attributes you can also check for any other boolean attribute or interpreter name:

Examples:

Query for the Opal interpreter

HostOS.interpreter.opal?

Query for TruffleRuby

HostOS.interpreter.truffleruby?

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cardinal?true, false (readonly) Also known as: parrot?

Returns whether the interpreter is the Parrot based Cardinal interpreter.

Returns:

  • (true, false)

    whether the interpreter is the Parrot based Cardinal interpreter



33
34
35
# File 'lib/host-os/interpreter.rb', line 33

def cardinal?
  id == :cardinal
end

.exeString? (readonly)

Path name of current Ruby executable.

Returns:

  • (String)

    complete path name to current Ruby executable

  • (nil)

    when executable can not be detected



98
99
100
# File 'lib/host-os/interpreter.rb', line 98

def exe
  defined?(@exe) ? @exe : @exe = find_exe
end

.idSymbol (readonly)

Returns interpreter identifier.

Returns:

  • (Symbol)

    interpreter identifier



# File 'lib/host-os/interpreter.rb', line 102

.jit_enabled?true, false (readonly)

Returns whether the interpreter currently uses a JIT Compiler.

Returns:

  • (true, false)

    whether the interpreter currently uses a JIT Compiler



65
66
67
# File 'lib/host-os/interpreter.rb', line 65

def jit_enabled?
  jit_type != :none
end

.jit_type:mjit, ... (readonly)

Returns type of currently used JIT Compiler.

Returns:

  • (:mjit, :rjit, :yjit, :java, :none)

    type of currently used JIT Compiler



72
73
74
75
76
77
# File 'lib/host-os/interpreter.rb', line 72

def jit_type
  return :mjit if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
  return :yjit if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
  return :rjit if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
  jruby? ? :java : :none
end

.jruby?true, false (readonly) Also known as: java?

Returns whether the interpreter is the Java based JRuby Interpreter.

Returns:

  • (true, false)

    whether the interpreter is the Java based JRuby Interpreter



41
42
43
# File 'lib/host-os/interpreter.rb', line 41

def jruby?
  id == :jruby
end

.mri?true, false (readonly) Also known as: cruby?, default?

Returns whether the interpreter is the Yukihiro Matsumoto's C-based (default) Ruby Interpreter.

Returns:

  • (true, false)

    whether the interpreter is the Yukihiro Matsumoto's C-based (default) Ruby Interpreter



24
25
26
# File 'lib/host-os/interpreter.rb', line 24

def mri?
  id == :mri
end

.rbx?true, false (readonly) Also known as: rubinius?

Returns whether the interpreter is the Rubinius Interpreter.

Returns:

  • (true, false)

    whether the interpreter is the Rubinius Interpreter



49
50
51
# File 'lib/host-os/interpreter.rb', line 49

def rbx?
  id == :rbx
end

.ree?true, false (readonly) Also known as: enterprise?

Returns whether the interpreter is the Ruby Enterprise Edition.

Returns:

  • (true, false)

    whether the interpreter is the Ruby Enterprise Edition



57
58
59
# File 'lib/host-os/interpreter.rb', line 57

def ree?
  id == :ree
end

Class Method Details

.is?(what) ⇒ true, false

Returns whether the interpreter is the given identifier.

Parameters:

  • what (Symbol, String)

    the identifier to check

Returns:

  • (true, false)

    whether the interpreter is the given identifier



# File 'lib/host-os/interpreter.rb', line 105