Module Units
In: lib/facets/more/units.rb

Units

This is a very extensive SI units system.

Usage

Here are some examples of usage.

  1.bit/s + 8.bytes/s
  (1.bit/s).to(byte/s)
  1.mile.to(feet)
  1.acre.to(yd**2)
  1.acre.to(sq_yd)
  1.gallon.to(self.L)
  1.lb.to(kg)
  1.m.s.to(m.s)
  1.sq_mi.to(km**2)
  1.mile.to(km)
  1.usd.to(twd)

Notes

The namespace for all unit related classes. Mixing this in has the additional effect of making Units.with_unit_converter available without the Units. prefix, as well as the shortcuts for creating Units (see Units#method_missing).

Methods

Classes and Modules

Module Units::Config
Class Units::Converter
Class Units::Unit
Class Units::Value

Public Instance methods

Executes the block with the current Converter changed to the given Converter. This allows to temporarily change the Converter used by default.

Example:

  with_unit_converter(:uk) {
    puts 1.cwt.to(lb) # => 112.0 lb
  }

  with_unit_converter(:us) {
    puts 1.cwt.to(lb) # => 100.0 lb
  }

See also Converter.current.

[Validate]