Measure::Length
Inherits JSON::Serializable < Comparable < Struct < Value < Object
Constructors
Instantiate a Length instance with the given magnitude and Unit.
Instance methods
Multiply by a scalar value
2.miles * 5
# => Measure::Length(@magnitude=10.0, @unit=Measure::Length::Unit::Mile)
Multiply by another Length to get an Area
2.meters * 3.meters
# => Measure::Area(@magnitude=6.0, @unit=Measure::Area::Unit::SquareMeter)
Add two Lengths of any units together, returning an instance using
self's Unit.
1.kilometer + 1.mile
# => Measure::Length(@magnitude=2.6093439485009937, @unit=Measure::Length::Unit::Kilometer)
Subtract a Length from self, returning an instance using self's
Unit.
1.mile - 1.kilometer
# => Measure::Length(@magnitude=0.37862878787878795, @unit=Measure::Length::Unit::Mile)
Divide by a scalar value
10.miles / 2
# => Measure::Length(@magnitude=5.0, @unit=Measure::Length::Unit::Mile)
Returns -1 if self is less than other, 0 if they're equal, or -1
otherwise.
1.mile <=> 1.kilometer # => 1
1.mile <=> 1.mile # => 0
1.kilometer <=> 1.mile # => -1
1.kilometer < 1.mile # => true
1.kilometer > 1.mile # => false
Returns true if self and other are close enough to each other to be
considered equivalent — within a femtometer (1/1_000_000_000_000_000th of
a meter). This isn't technically correct, but if you need that level of
precision, open an issue
and we can discuss how to support it.
Return the cube of this length as a Volume
2.meters.cubed
# => Measure::Volume(@magnitude=8.0, @unit=Measure::Volume::Unit::CubicMeter)
Return the square of this length as an Area
2.meters.squared
# => Measure::Area(@magnitude=4.0, @unit=Measure::Area::Unit::SquareMeter)
Convert this instance to the given Unit.
1.mile.to(:feet)
# => Measure::Length(@magnitude=5280.0, @unit=Measure::Length::Unit::Foot)