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



125
126
127
# File 'lib/host-os.rb', line 125

def cardinal?
  ID == :cardinal
end

.idSymbol (readonly)

Returns interpreter identifier.

Returns:

  • (Symbol)

    interpreter identifier



109
110
111
# File 'lib/host-os.rb', line 109

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



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

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



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

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



133
134
135
# File 'lib/host-os.rb', line 133

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



116
117
118
# File 'lib/host-os.rb', line 116

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



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

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



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

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 176