File: README.md

package info (click to toggle)
ruby-os 1.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 136 kB
  • sloc: ruby: 474; makefile: 3
file content (104 lines) | stat: -rw-r--r-- 2,596 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
The OS gem allows for some easy telling if you're on windows or not. 

```ruby
require 'os'

>> OS.windows?
=> true   # or OS.doze?

>> OS.bits
=> 32

>> OS.java?
=> true # if you're running in jruby.  Also OS.jruby?

>> OS.ruby_bin
=> "c:\ruby18\bin\ruby.exe" # or "/usr/local/bin/ruby" or what not

>> OS.posix?
=> false # true for linux, os x, cygwin

>> OS.mac? # or OS.osx? or OS.x?
=> false

>> OS.dev_null
=> "NUL" # or "/dev/null" depending on which platform

>> OS.rss_bytes
=> 12300033 # number of rss bytes this process is using currently.  Basically "total in memory footprint" (doesn't include RAM used by the process that's in swap/page file)

>> puts OS.report
==> # a yaml report of helpful values
--- 
arch: x86_64-darwin10.6.0
target_os: darwin10.6.0
target_vendor: apple
target_cpu: x86_64
target: x86_64-apple-darwin10.6.0
host_os: darwin10.6.0
host_vendor: apple
host_cpu: i386
host: i386-apple-darwin10.6.0
RUBY_PLATFORM: x86_64-darwin10.6.0

>> OS.cpu_count  
=> 2 # number of cores, doesn't include hyper-threaded cores.

>> OS.open_file_command
=> "start" # or open on mac, or xdg-open on linux (all designed to open a file)

>> OS::Underlying.windows?
=> true # true for cygwin or MRI, whereas OS.windows? is false for cygwin

>> OS::Underlying.bsd?
=> true # true for OS X

>> OS::Underlying.docker?
=> false # true if running inside a Docker container

>> pp OS.parse_os_release
==> # A hash of details on the current Linux distro (or an exception if not Linux)
{:NAME=>"Ubuntu",
 :VERSION=>"18.04.4 LTS (Bionic Beaver)",
 :ID=>"ubuntu",
 :ID_LIKE=>"debian",
 :PRETTY_NAME=>"Ubuntu 18.04.4 LTS",
 :VERSION_ID=>"18.04",
 :HOME_URL=>"https://www.ubuntu.com/",
 :SUPPORT_URL=>"https://help.ubuntu.com/",
 :BUG_REPORT_URL=>"https://bugs.launchpad.net/ubuntu/",
 :PRIVACY_POLICY_URL=>
  "https://www.ubuntu.com/legal/terms-and-policies/privacy-policy",
 :VERSION_CODENAME=>"bionic",
 :UBUNTU_CODENAME=>"bionic"}
```
  
If there are any other features you'd like, let me know, I'll do what I can to add them :)

http://github.com/rdp/os for feedback et al

Related projects:

rubygems:

```ruby
Gem::Platform.local
Gem.ruby
```

  The reason Gem::Platform.local felt wrong to me is that it treated cygwin as windows--which for most build environments, is wrong.  Hence the creation of this gem.

the facets gem (has a class similar to rubygems, above)

```ruby
require 'facets/platform'
Platform.local
```

the ["platform" gem](http://rubydoc.info/github/ffi/ffi/master/FFI/Platform), itself (a different gem)

```ruby
FFI::Platform::OS
```

License: MIT (see LICENSE file)