A class whose instances consist of "value (physical quantity)" and "unit". Featuring:
require 'quanty'
Quanty(1.23,'km') + Quanty(4.56,'m') #=> Quanty(1.23456,'km')
Quanty(123,'mile') / Quanty(2,'hr') #=> Quanty(61,'mile / hr')
Quanty(61,'miles/hr').want('m/s') #=> Quanty(27.26944,'m/s')
Quanty(1.0,'are') == Quanty(10,'m')**2 #=> true
Math.cos(Quanty(60,'degree')) #=> 0.5
Object (Numeric is better??)
Quanty.new([value],[unit])Quanty([value],[unit])Create Quanty class instance having value and unit (is String). If value is omitted, value = 1 is assumed. If unit is omitted, unit = "" is assumed, which is regarded as a quantity with "dimensionless" unit (i.e. all dimensions of unit are zero). Refer to Notation of unit below.
self + otherself - otherAddition and subtraction of quantities. Operation is made after the unit of other is converted to the unit of self. Exception is raised if unit conversion is failed. Return the Quanty class instance with the unit of self.
self * otherMultiplication of quantities. Resulting unit is made by concatenating self and other.
self / otherDivision of quantities.
Resulting unit is made by placing "/"
between self and other, and concatenating them.
self ** numberPower of quantities. Resulting unit is made by "(unit of self)^number"
self == otherself < otherself <= otherself > otherself >= otherComparison of quantities.
coerce(number)Convert number to Quanty class instance with dimensionless unit, then return [number, self].
to_sito_SIConvert self to the SI unit system.
to_fIf self is a quantity with a dimensionless unit, return its value. If self is a quantity with an angular unit, return the value converted into radian. Otherwise, raise exception.
unitReturn the string of unit.
valvalueReturn the value.
want(unit)Convert self to a quantity with unit (is String), and return Quanty class instance.
'N m' == 'N*m'
'/s' , 'm/s'
'm-2' == 'm^-2' == 'm**-2'
'12 inch' == 'feet'
'm/s*m' == 'm^2/s'. 'm/(s*m)' == '/s'.
Masahiro Tanaka (2001-04-25)