Module: Os

Includes:
Contracts::Modules
Defined in:
lib/specs.rb

Overview

Get the basic operating system name reliably, even in JRuby Useful for OS-contextual command line instructions.

E.g., ‘C:Program Files (x86)Mozilla Firefoxfirefox –version’ in Windows vs

'/Applications/Firefox.app/Contents/MacOS/firefox --version' in Mac vs
'firefox --version' in Unix

Class Method Summary collapse

Class Method Details

.haiku?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/specs.rb', line 67

def self.haiku?
  raw =~ /haiku/
end

.linux?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/specs.rb', line 72

def self.linux?
  self.unix? && !(self.mac? || self.haiku?)
end

.mac?Boolean

Returns:

  • (Boolean)


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

def self.mac?
  raw =~ /darwin/
end

.mingw?Boolean

Returns:

  • (Boolean)


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

def self.mingw?
  raw =~ /cygwin|mingw/
end

.os_nameObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/specs.rb', line 87

def self.os_name
  if self.windows?
    :windows
  elsif self.mac?
    :mac
  elsif self.linux?
    :linux
  elsif self.haiku?
    :haiku
  else
    :unix
  end
end

.rawObject



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

def self.raw
  # Config deprecated in Ruby 1.9
  RbConfig::CONFIG['host_os']
end

.unix?Boolean

Returns:

  • (Boolean)


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

def self.unix?
  !self.windows?
end

.windows?Boolean

Returns:

  • (Boolean)


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

def self.windows?
  raw =~ /cygwin|mswin|mingw|bccwin|wince|emx/
end

.x86?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/specs.rb', line 82

def self.x86?
  !self.x86_64?
end

.x86_64?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/specs.rb', line 77

def self.x86_64?
  RbConfig::CONFIG['arch'] =~ /64/
end