struct Measure::Length
- Measure::Length
- Struct
- Value
- Object
Included Modules
- Comparable(Measure::Length)
- JSON::Serializable
Defined in:
length.crConstructors
-
.new(magnitude : Float64, unit : Measure::Length::Unit)
Instantiate a
Lengthinstance with the given#magnitudeandUnit. - .new(pull : JSON::PullParser)
Instance Method Summary
-
#*(scalar : Number) : self
Multiply by a scalar value
- #+(other : self) : self
- #-(other : self) : self
-
#/(scalar : Number) : self
Multiply by a scalar value
-
#<=>(other : self)
Returns
-1ifselfis less thanother,0if they're equal, or-1otherwise. -
#==(other : self)
Returns
trueifselfandotherare close enough to each other to be considered equivalent — within a femtometer (1/1_000_000_000_000_000th of a meter). -
#magnitude : Float64
The numeric part of the measurement — the
1in1.meter. -
#to(unit : Unit) : self
Convert this instance to the given
Unit. -
#to_s(io : IO) : Nil
Output a human-readable representation of this
Lengthto the givenIO. -
#total_meters : Float64
Returns the number of meters represented by this
Lengthinstance -
#unit : Unit
The unit used in measuring the length.
Constructor Detail
Instantiate a Length instance with the given #magnitude and Unit.
Instance Method Detail
Multiply by a scalar value
2.miles * 5
# => Measure::Length(@magnitude=10.0, @unit=Measure::Length::Unit::Mile)
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)
Multiply 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.
Convert this instance to the given Unit.
1.mile.to(:feet)
# => Measure::Length(@magnitude=5280.0, @unit=Measure::Length::Unit::Foot)