Module: HostOS::Interpreter

Defined in:
lib/host-os.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?

Constant Summary collapse

ID =

Returns interpreter identifier.

Returns:

  • (Symbol)

    interpreter identifier

identify

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



127
128
129
# File 'lib/host-os.rb', line 127

def cardinal?
  ID == :cardinal
end

.idSymbol (readonly)

Returns interpreter identifier.

Returns:

  • (Symbol)

    interpreter identifier



111
112
113
# File 'lib/host-os.rb', line 111

def id
  ID
end

.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



158
159
160
# File 'lib/host-os.rb', line 158

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



165
166
167
168
169
170
# File 'lib/host-os.rb', line 165

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



135
136
137
# File 'lib/host-os.rb', line 135

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



118
119
120
# File 'lib/host-os.rb', line 118

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



142
143
144
# File 'lib/host-os.rb', line 142

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



150
151
152
# File 'lib/host-os.rb', line 150

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.rb', line 192