class Sys::Uname

The Uname class encapsulates information about the system.

The Uname class encapsulates uname (platform) information.

Constants

BUFSIZE
CTL_HW
HW_MODEL
SI_ARCHITECTURE
SI_DHCP_CACHE
SI_HOSTNAME
SI_HW_PROVIDER
SI_HW_SERIAL
SI_ISALIST
SI_MACHINE
SI_PLATFORM
SI_RELEASE
SI_SRPC_DOMAIN
SI_SYSNAME
SI_VERSION
UnameStruct

The UnameStruct is used to store platform information for some methods.

VERSION

The version of the sys-uname gem.

Public Class Methods

architecture() click to toggle source

The basic instruction set architecture of the current system, e.g. sparc, i386, etc.

# File lib/sys/unix/uname.rb, line 205
def self.architecture
  uname.architecture
end
dhcp_cache() click to toggle source

The string consisting of the ASCII hexidecimal encoding of the name of the interface configured by boot(1M) followed by the DHCPACK reply from the server.

# File lib/sys/unix/uname.rb, line 219
def self.dhcp_cache
  uname.dhcp_cache
end
hw_provider() click to toggle source

The name of the of the hardware provider.

# File lib/sys/unix/uname.rb, line 239
def self.hw_provider
  uname.hw_provider
end
hw_serial() click to toggle source

The ASCII representation of the hardware-specific serial number of the physical machine on which the function is executed.

# File lib/sys/unix/uname.rb, line 233
def self.hw_serial
  uname.hw_serial.to_i
end
isa_list() click to toggle source

The variant instruction set architectures executable on the current system.

# File lib/sys/unix/uname.rb, line 226
def self.isa_list
  uname.isa_list
end
machine() click to toggle source

Returns the machine hardware type.

Example:

Uname.machine # => 'i686'
# File lib/sys/unix/uname.rb, line 185
def self.machine
  uname.machine
end
model() click to toggle source

Returns the model type.

Example:

Uname.model # => 'MacBookPro5,3'
# File lib/sys/unix/uname.rb, line 196
def self.model
  uname.model
end
nodename() click to toggle source

Returns the name of this node within the communications network to which this node is attached, if any. This is often, but not necessarily, the same as the host name.

Example:

Uname.nodename # => 'your_host.foo.com'
# File lib/sys/unix/uname.rb, line 155
def self.nodename
  uname.nodename
end
platform() click to toggle source

The specific model of the hardware platform, e.g Sun-Blade-1500, etc.

# File lib/sys/unix/uname.rb, line 211
def self.platform
  uname.platform
end
release() click to toggle source

Returns the current release level of your operating system.

Example:

Uname.release # => '2.2.16-3'
# File lib/sys/unix/uname.rb, line 165
def self.release
  uname.release
end
srpc_domain() click to toggle source

The Secure Remote Procedure Call domain name.

# File lib/sys/unix/uname.rb, line 245
def self.srpc_domain
  uname.srpc_domain
end
sysname() click to toggle source

Returns the name of this implementation of the operating system.

Example:

Uname.sysname # => 'Darwin'
# File lib/sys/unix/uname.rb, line 143
def self.sysname
  uname.sysname
end
uname() click to toggle source

Returns a struct that contains the sysname, nodename, machine, version and release of your system.

On OS X and BSD platforms it will also include the model.

On HP-UX, it will also include the id_number.

Example:

require 'sys/uname'

p Sys::Uname.uname
# File lib/sys/unix/uname.rb, line 109
    def self.uname
      utsname = UnameFFIStruct.new

      raise Error, 'uname() function call failed' if uname_c(utsname) < 0

      struct = UnameStruct.new
      struct[:sysname]  = utsname[:sysname].to_s
      struct[:nodename] = utsname[:nodename].to_s
      struct[:release]  = utsname[:release].to_s
      struct[:version]  = utsname[:version].to_s
      struct[:machine]  = utsname[:machine].to_s

      struct[:model] = get_model() if RbConfig::CONFIG['host_os'] =~ /darwin|bsd|dragonfly/i
      struct[:id_number] = utsname[:__id_number].to_s if RbConfig::CONFIG['host_os'] =~ /hpux/i
      struct[:domainname] = utsname[:domainname].to_s if RbConfig::CONFIG['host_os'] =~ /linux/i

      # Let's add a members method that works for testing and compatibility
      if struct.members.nil?
        struct.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
          def members
            @table.keys.map(&:to_s)
          end
        RUBY
      end

      struct.freeze
    end
version() click to toggle source

Returns the current version level of your operating system.

Example:

Uname.version # => '5.9'
# File lib/sys/unix/uname.rb, line 175
def self.version
  uname.version
end

Private Class Methods

convert(str) click to toggle source

There is a bug in win32ole where uint64 types are returned as a String rather than a Fixnum/Bignum. This deals with that for now.

# File lib/sys/windows/uname.rb, line 492
def self.convert(str)
  return nil if str.nil? # Don't turn nil into 0
  str.to_i
end
get_model() click to toggle source

Returns the model for systems that define sysctl().

# File lib/sys/unix/uname.rb, line 254
def self.get_model
  buf  = 0.chr * BUFSIZE
  mib  = FFI::MemoryPointer.new(:int, 2).write_array_of_int([CTL_HW, HW_MODEL])
  size = FFI::MemoryPointer.new(:long, 1).write_int(buf.size)

  sysctl(mib, 2, buf, size, nil, 0)

  buf.strip
end
parse_ms_date(str) click to toggle source

Converts a string in the format ‘20040703074625.015625-360’ into a Ruby Time object.

# File lib/sys/windows/uname.rb, line 482
def self.parse_ms_date(str)
  return if str.nil?
  Time.parse(str.split('.')[0])
end