Module: Os

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:



79
80
81
# File 'lib/specs.rb', line 79

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

.linux?Boolean

Returns:



84
85
86
# File 'lib/specs.rb', line 84

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

.mac?Boolean

Returns:



69
70
71
# File 'lib/specs.rb', line 69

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

.mingw?Boolean

Returns:



64
65
66
# File 'lib/specs.rb', line 64

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

.os_nameObject



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/specs.rb', line 99

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



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

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

.unix?Boolean

Returns:



74
75
76
# File 'lib/specs.rb', line 74

def self.unix?
  !self.windows?
end

.windows?Boolean

Returns:



59
60
61
# File 'lib/specs.rb', line 59

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

.x86?Boolean

Returns:



94
95
96
# File 'lib/specs.rb', line 94

def self.x86?
  !self.x86_64?
end

.x86_64?Boolean

Returns:



89
90
91
# File 'lib/specs.rb', line 89

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