struct
Measure::Volume
- Measure::Volume
- Struct
- Value
- Object
Included Modules
- Comparable(Measure::Volume)
Defined in:
volume.crConstructors
-
.new(magnitude : Float64, unit : Measure::Volume::Unit)
Instantiate a
Volumeinstance with the given#magnitudeandUnit.
Instance Method Summary
-
#*(scalar : Number) : self
Multiply by a scalar value
- #+(other : self) : self
- #-(other : self) : self
-
#/(scalar : Number) : self
Divide by a scalar value
-
#<=>(other : self)
Returns
-1ifselfis less thanother,0if they're equal, or1otherwise. -
#==(other : self)
Returns
trueifselfandotherare close enough to each other to be considered equivalent. -
#magnitude : Float64
The numeric part of the measurement — the
1in1.liter. -
#to(unit : Unit) : self
Convert this instance to the given
Unit. -
#to_s(io : IO) : Nil
Output a human-readable representation of this
Volumeto the givenIO. -
#total_liters : Float64
Returns the number of liters represented by this
Volumeinstance -
#unit : Unit
The unit used in measuring the volume.
Constructor Detail
Instantiate a Volume instance with the given #magnitude and Unit.
Instance Method Detail
Multiply by a scalar value
2.liters * 5
# => Measure::Volume(@magnitude=10.0, @unit=Measure::Volume::Unit::Liter)
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)
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)
Divide by a scalar value
10.liters / 2
# => Measure::Volume(@magnitude=5.0, @unit=Measure::Volume::Unit::Liter)
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
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.
Convert this instance to the given Unit.
1.gallon.to(:liters)
# => Measure::Volume(@magnitude=3.78541, @unit=Measure::Volume::Unit::Liter)