Module: Runtime

Defined in:
lib/runtime_info.rb

Overview

Interfaces to various Ruby virtual machine and platform specifics

Class Method Summary collapse

Class Method Details

.archObject

Host CPU architecture



16
# File 'lib/runtime_info.rb', line 16

def arch; Config::CONFIG['host_cpu']; end

.cpu_architectureObject



17
# File 'lib/runtime_info.rb', line 17

def cpu_architecture; arch; end

.cpu_countObject



30
# File 'lib/runtime_info.rb', line 30

def cpu_count; ncpus; end

.engineObject

Ruby virtual machine in use



38
39
40
41
# File 'lib/runtime_info.rb', line 38

def engine
  return RUBY_ENGINE if defined? RUBY_ENGINE
  'ruby'
end

.ncpusObject

Number of physical CPU cores



20
21
22
23
24
25
26
27
28
29
# File 'lib/runtime_info.rb', line 20

def ncpus
  case os
  when 'darwin'
    Integer(`hwprefs cpu_count`)
  when 'linux'
    cores = File.read("/proc/cpuinfo").scan(/core id\s+: \d+/).uniq.size
    cores > 0 ? cores : 1
  else raise "don't know how to determine CPU count on #{os}"
  end
end

.osObject

Host OS



33
34
35
# File 'lib/runtime_info.rb', line 33

def os
  Config::CONFIG['host_os'][/^[A-Za-z]+/]
end

.pathObject

Path to the Ruby interpreter currently in use



54
# File 'lib/runtime_info.rb', line 54

def path; Gem.ruby; end

.platformObject

A platform identifier containing CPU and OS information



13
# File 'lib/runtime_info.rb', line 13

def platform; RUBY_PLATFORM; end

.versionObject

Version of the Ruby virtual machine in use



44
45
46
47
48
49
50
51
# File 'lib/runtime_info.rb', line 44

def version
  case engine
  when 'ruby'  then RUBY_VERSION
  when 'jruby' then JRUBY_VERSION
  when 'rbx'   then Rubinius::VERSION
  else raise "don't know how to obtain version for #{engine}"
  end
end