Measure::Weight
Inherits Comparable < Struct < Value < Object
Constructors
Instantiate a Weight instance with the given magnitude and Unit.
Instance methods
*(scalar : Number) : self
Multiply by a scalar value
2.kg * 5
# => Measure::Length(@magnitude=10.0, @unit=Measure::Length::Unit::Kilogram)
+(other : self) : self
Add two Weights of any units together, returning an instance using
self's Unit.
1.kilogram + 1.pound
# => Measure::Weight(@magnitude=1.4535929094356397, @unit=Measure::Weight::Unit::Kilogram)
-(other : self) : self
Subtract a Length from self, returning an instance using self's
Unit.
1.kilogram - 1.pound
# => Measure::Weight(@magnitude=0.5464070905643603, @unit=Measure::Weight::Unit::Kilogram)
/(scalar : Number) : self
Multiply by a scalar value
10.kg / 2
# => Measure::Length(@magnitude=2.0, @unit=Measure::Length::Unit::Kilogram)
<=>(other : self)
Returns -1 if self is less than other, 0 if they're equal, or -1
otherwise.
1.kg <=> 1.lb # => 1
1.lb <=> 1.lb # => 0
1.lb <=> 1.kg # => -1
1.lb < 1.kg # => true
1.lb > 1.kg # => false
==(other : self)
Returns true if self and other are close enough to each other to be
considered equivalent — within a femtogram (1/1_000_000_000_000_000th of
a gram). This isn't technically correct, but if you need that level of
precision, open an issue
and we can discuss how to support it.
to(unit : Unit) : self
Convert this instance to the given Unit.
1.kilogram.to(:lbs)
# => Measure::Weight(@magnitude=2.20462, @unit=Measure::Weight::Unit::Pound)