Class: MemInfo
- Inherits:
-
Object
- Object
- MemInfo
- Defined in:
- lib/mem_info.rb
Instance Method Summary collapse
-
#mem_total ⇒ Object
Total memory in kb.
- #unknown? ⇒ Boolean
Instance Method Details
#mem_total ⇒ Object
Total memory in kb. On Mac OS uses “sysctl”, elsewhere expects the system has /proc/meminfo. Returns nil if it cannot be determined.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mem_info.rb', line 6 def mem_total @mem_total ||= begin system = `uname`.strip if system == "Darwin" s = `sysctl -n hw.memsize`.strip s.to_i / 1.kilobyte else s = `grep MemTotal /proc/meminfo` /(\d+)/.match(s)[0].try(:to_i) end rescue StandardError nil end end |
#unknown? ⇒ Boolean
22 23 24 |
# File 'lib/mem_info.rb', line 22 def unknown? mem_total.nil? end |