https://github.com/yegor256/total
Ruby Gem to get total memory size in the system
https://github.com/yegor256/total
memory memory-management ruby ruby-gem
Last synced: about 1 year ago
JSON representation
Ruby Gem to get total memory size in the system
- Host: GitHub
- URL: https://github.com/yegor256/total
- Owner: yegor256
- License: mit
- Created: 2018-12-28T12:25:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-08T15:59:51.000Z (about 1 year ago)
- Last Synced: 2025-04-09T22:13:23.629Z (about 1 year ago)
- Topics: memory, memory-management, ruby, ruby-gem
- Language: Ruby
- Homepage: https://rubygems.org/gems/total
- Size: 215 KB
- Stars: 17
- Watchers: 3
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README

[](https://www.elegantobjects.org)
[](https://www.rultor.com/p/yegor256/total)
[](https://www.jetbrains.com/ruby/)
[](https://github.com/yegor256/total/actions/workflows/rake.yml)
[](https://badge.fury.io/rb/total)
[](https://codeclimate.com/github/yegor256/total/maintainability)
[](https://rubydoc.info/github/yegor256/total/master/frames)
[](https://github.com/yegor256/total/sibit/master/LICENSE.txt)
[](https://codecov.io/github/yegor256/total?branch=master)
[](https://hitsofcode.com/view/github/yegor256/total)
Total is a Ruby gem to detect the total amount of memory in the system.
First, install it:
```bash
$ gem install total
```
Then, use it like this:
```ruby
require 'total'
puts Total::Mem.new.bytes
```
The following platforms are supported:
* MacOSX
* Linux
* FreeBSD
* Windows ([help wanted](https://github.com/yegor256/total/issues/3))
If the platform is not recognized or is not supported, `Total::CantDetect` exception
will be raised. You should catch it and proceed accordingly, for example:
```ruby
def total_mb
Total::Mem.new.bytes / (1024 * 1024)
rescue Total::CantDetect
512
end
```
This code will return the actual memory size in Mb, if it can be detected,
or 512 otherwise.
That's it.
## How to contribute
Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
Make sure your build is green before you contribute
your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
[Bundler](https://bundler.io/) installed. Then:
```
$ bundle update
$ bundle exec rake
```
If it's clean and you don't see any error messages, submit your pull request.