Measure::Volume
Inherits Comparable < Struct < Value < Object
Constructors
Instantiate a Volume instance with the given magnitude and Unit.
Instance methods
*(scalar : Number) : self
Multiply by a scalar value
2.liters * 5
# => Measure::Volume(@magnitude=10.0, @unit=Measure::Volume::Unit::Liter)
+(other : self) : self
Add two Volumes of any units together, returning an instance using
self's Unit.
1.liter + 1.gallon
# => Measure::Volume(@magnitude=4.78541, @unit=Measure::Volume::Unit::Liter)
-(other : self) : self
Subtract a Volume from self, returning an instance using self's
Unit.
1.gallon - 1.liter
# => Measure::Volume(@magnitude=0.735764, @unit=Measure::Volume::Unit::Gallon)
/(scalar : Number) : self
Divide by a scalar value
10.liters / 2
# => Measure::Volume(@magnitude=5.0, @unit=Measure::Volume::Unit::Liter)
<=>(other : self)
Returns -1 if self is less than other, 0 if they're equal, or 1
otherwise.
1.gallon <=> 1.liter # => 1
1.liter <=> 1.liter # => 0
1.liter <=> 1.gallon # => -1
1.liter < 1.gallon # => true
1.liter > 1.gallon # => false
==(other : self)
Returns true if self and other are close enough to each other to be
considered equivalent. 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.gallon.to(:liters)
# => Measure::Volume(@magnitude=3.78541, @unit=Measure::Volume::Unit::Liter)