Get Total Memory Size
This Ruby gem helps you detect the total amount of memory in the system.
First, install it:
gem install total
Then, use it like this:
require 'total'
puts Total::Mem.new.bytes
The following platforms are supported:
- MacOSX
- Linux
- FreeBSD
- Windows (including MSYS2/MinGW, MSVC, and Cygwin environments)
If the platform is not recognized or is not supported,
the Total::CantDetect exception is raised.
You catch it and proceed accordingly, for example:
def total_mb
Total::Mem.new.bytes / (1024 * 1024)
rescue Total::CantDetect
512
end
This code returns the actual memory size in Mb, if it can be detected, or 512 otherwise.
That's it.
How to contribute
Read these guidelines. Make sure your build is green before you contribute your pull request. You need to have Ruby 2.3+ and Bundler installed. Then:
bundle update
bundle exec rake
If it's clean and you don't see any error messages, submit your pull request.