Class: Sys::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/sys/platform.rb,
lib/sys/uname.rb

Overview

The Platform class provides singleton methods to tell you what OS you’re on.

Constant Summary collapse

VERSION =

The version of the sys-uname gem.

Uname::VERSION
ARCH =

The CPU architecture

File::ALT_SEPARATOR ? Uname.architecture.to_sym : Uname.machine.to_sym
OS =

Returns a basic OS family, either :windows or :unix

File::ALT_SEPARATOR ? :windows : :unix
IMPL =

Returns the OS type, :macosx, :linux, :mingw32, etc

case Uname.sysname
  when /darwin|mac/i
    :macosx
  when /mingw|windows/i
    require 'rbconfig'
    RbConfig::CONFIG['host_os'].split('_').first[/[a-z]+/i].downcase.to_sym
  when /linux/i
    :linux
  when /bsd|dragonfly/i
    :bsd
end

Class Method Summary collapse

Class Method Details

.bsd?Boolean

Returns whether or not you’re on any BSD platform

Returns:

  • (Boolean)


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

def self.bsd?
  Uname.sysname =~ /bsd/i ? true : false
end

.linux?Boolean

Returns whether or not you’re on Linux

Returns:

  • (Boolean)


42
43
44
# File 'lib/sys/platform.rb', line 42

def self.linux?
  Uname.sysname =~ /linux/i ? true : false
end

.mac?Boolean

Returns whether or not you’re on a mac, i.e. OSX

Returns:

  • (Boolean)


37
38
39
# File 'lib/sys/platform.rb', line 37

def self.mac?
  Uname.sysname =~ /darwin|mac/i ? true : false
end

.unix?Boolean

Returns whether or not you’re on a Unixy (non-Windows) OS

Returns:

  • (Boolean)


32
33
34
# File 'lib/sys/platform.rb', line 32

def self.unix?
  Uname.sysname =~ /microsoft/i ? false : true
end

.windows?Boolean

Returns whether or not you’re on a Windows OS

Returns:

  • (Boolean)


27
28
29
# File 'lib/sys/platform.rb', line 27

def self.windows?
  Uname.sysname =~ /microsoft/i ? true : false
end