Class: OS

Inherits:
Object
  • Object
show all
Defined in:
lib/os.rb

Class Method Summary collapse

Class Method Details

.bitsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/os.rb', line 50

def self.bits
  @bits ||= begin
    require 'rbconfig'
    if RbConfig::CONFIG['host_cpu'] =~ /_64$/ # x86_64
      64
    elsif RbConfig::CONFIG['host_os'] =~ /32$/ # mingw32, mswin32
      32
    else # cygwin only...I think
      if 1.size == 8
        64
      else
        32
      end
    end
  end
end

.java?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
75
76
# File 'lib/os.rb', line 68

def self.java?
  @java ||= begin
    if RUBY_PLATFORM =~ /java/
      true
    else
      false
    end
  end
end

.mac?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/os.rb', line 86

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

.posix?Boolean

true for linux, os x, cygwin

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/os.rb', line 24

def self.posix?
  @posix ||=
  begin
    if OS.windows?
      begin
        begin
          # what if we're on interix...
          # untested, of course
          Process.wait fork{}
          true
        rescue NotImplementedError
          false
        end
      end
    else
      # assume non windows is posix
      true
    end
  end

end

.ruby_binObject



78
79
80
81
82
83
84
# File 'lib/os.rb', line 78

def self.ruby_bin
  @ruby_exe ||= begin
    require 'rbconfig'
    config = RbConfig::CONFIG
    File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
  end
end

.windows?Boolean Also known as: doze?

OS.windows? true if on windows [and/or jruby] false if on linux or cygwin

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/os.rb', line 10

def self.windows?
  @windows ||= begin
    if RUBY_PLATFORM =~ /cygwin/ # i386-cygwin
      false
    elsif ENV['OS'] == 'Windows_NT'
      true
    else
      false
    end
  end

end