Module: System::OS

Defined in:
lib/system/os.rb

Overview

Information about the current Operating System (OS) running on the current system.

Since:

  • 0.1.1

Constant Summary collapse

Unknown =

Unknown OS

Since:

  • 0.1.1

:unknown
Linux =

Any OS running the Linux kernel

Since:

  • 0.1.1

:linux
Windows =

Any Windows OS

Since:

  • 0.1.1

:windows
Solaris =

Any Solaris OS

Since:

  • 0.1.1

:solaris
BSD =

Any OS running the BSD kernel

Since:

  • 0.1.1

:bsd
OSX =

Any OSX OS

Since:

  • 0.1.1

:osx
Darwin =

Any OS running the Darwin kernel

Since:

  • 0.1.1

:darwin

Class Method Summary collapse

Class Method Details

.bsd?TrueClass, FalseClass

Get if the name of the operating system running on the current host is ‘System::OS::BSD`.

Examples:

System::OS.name # => :bsd
System::OS.bsd? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/os.rb', line 67

.darwin?TrueClass, FalseClass

Get if the name of the operating system running on the current host is ‘System::OS::Darwin`.

Examples:

System::OS.name # => :darwin
System::OS.darwin? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



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

[Linux, Windows, Solaris, BSD, OSX, Darwin].each do |name|
  define_method("#{name}?") { self.name == name }
end

.linux?TrueClass, FalseClass

Get if the name of the operating system running on the current host is ‘System::OS::Linux`.

Examples:

System::OS.name # => :linux
System::OS.linux? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/os.rb', line 40

.nameSymbol

Get the name of the operating system running on the current host.

Examples:

Return OS name

System::OS.name # => :osx

Assert current OS

System::OS.name == System::OS::OSX # => true

Returns:

  • (Symbol)

    The name of the operating system.

Since:

  • 0.1.1



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/system/os.rb', line 106

def name
  return @name if defined?(@name)
  
  os_name = System::Ruby.platform
  os_name = RbConfig::CONFIG['host_os'] if defined?(RbConfig::CONFIG)
  os_name = System.getProperty('os.name').downcase if System::Ruby.jruby?
  
  @name = case os_name
  when /linux/ then Linux
  when /solaris/ then Solaris
  when /bsd/ then BSD
  when /darwin/ then
    defined?(RbConfig::CONFIG) && RbConfig::CONFIG['build_vendor'] == 'apple' ? OSX : Darwin
  when /mac.*?os.*?x/ then OSX
  when /win/ then Windows # TODO: "win" is in the word "darwin"... had to move down here but need better examples of Windows OS name results...
  else
    Unknown
  end
end

.osx?TrueClass, FalseClass

Get if the name of the operating system running on the current host is ‘System::OS::OSX`.

Examples:

System::OS.name # => :osx
System::OS.osx? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/os.rb', line 76

.solaris?TrueClass, FalseClass

Get if the name of the operating system running on the current host is ‘System::OS::Solaris`.

Examples:

System::OS.name # => :solaris
System::OS.solaris? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/os.rb', line 58

.windows?TrueClass, FalseClass

Get if the name of the operating system running on the current host is ‘System::OS::Windows`.

Examples:

System::OS.name # => :windows
System::OS.windows? # => true

Returns:

  • (TrueClass, FalseClass)

Since:

  • 0.1.3



# File 'lib/system/os.rb', line 49