4. The MacTypes::Units
class
The Units
class represents a measurement of some sort, e.g. 3 inches, 98.5 degrees Fahrenheit.
class Units
Constructor:
Units.new(value, type)
value : Fixnum | Bignum | Float -- the amount, e.g. 3.5
type : Symbol -- the unit of measurement, e.g. :centimeters
Methods:
==
hash
inspect
value -- returns the amount
type -- returns the unit of measurement
to_i -- returns the amount as an integer
to_f -- returns the amount as a float
to_s -- returns the measurement as a string, e.g. "3.5 centimeters"
The following unit types are defined as standard:
:centimeters :cubic_inches
:meters :cubic_feet
:kilometers :cubic_yards
:inches
:feet :liters
:yards :quarts
:miles :gallons
:square_meters :grams
:square_kilometers :kilograms
:square_feet :ounces
:square_yards :pounds
:square_miles
:degrees_Celsius
:cubic_centimeters :degrees_Fahrenheit
:cubic_meters :degrees_Kelvin
Additional application-specific unit types can be added if needed.
Examples
MacTypes::Units.new(14, :inches)
MacTypes::Units.new(3.5, :square_meters)