Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Ruby Gem for Measurements

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 locales
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 GPL-LICENSE.txt
Octocat-spinner-32 Gemfile
Octocat-spinner-32 MIT-LICENSE.txt
Octocat-spinner-32 Rakefile
Octocat-spinner-32 m9t.gemspec

m9t Build Status

Measurements and coversions library for Ruby

This package handles the basic units of measure:

  • distance,
  • direction,
  • speed,
  • temperature,
  • weight.

The emphasis is on:

  • coherent interface,
  • ease of translation (using i18n).


Internally, values are stored in SI units, with the exception of temperature:

  • distance - meters,
  • direction - degrees,
  • speed - meters per second,
  • temperature - degrees celcius,
  • weight - kilograms.


new: accepts the S.I. unit as a parameter:

height =

to_f: returns the decimal value(s):

height.to_f -> 1.75

other units: there are class methods named after each known unit, which take values in that unit (actually, they are defined as needed):

marathon = M9t::Distance.miles(26.21875)
marathon.to_f -> 42194.988

to_s: returns a localized string with units:

I18n.locale = :it
puts -> '3 metri'

Class methods for conversion

Methods are available for conversion between any pair of units:

M9t::Distance.miles_to_meters(26.21875) -> 42194.988



ruby 1.8.x (not jruby):

$ rake rcov

ruby 1.9.x:

$ COVERAGE=1 rake test


  • ruby-units
    • Doesn't handle i18n:
      • The library depends heavily on English string representations of units.
    • Monkey patches a lot of core classes:
      • Adds methods to e.g. Object.



Dual license:

  • MIT License: see MIT-LICENSE.txt,
  • GPL version 3: see GPL-LICENSE.txt
Something went wrong with that request. Please try again.