struct Measure::Weight
- Measure::Weight
- Struct
- Value
- Object
Included Modules
- Comparable(Measure::Weight)
Defined in:
weight.crConstructors
-
.new(magnitude : Float64, unit : Measure::Weight::Unit)
Instantiate a
Weight
instance with the given#magnitude
andUnit
.
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
-1
ifself
is less thanother
,0
if they're equal, or-1
otherwise. -
#==(other : self)
Returns
true
ifself
andother
are close enough to each other to be considered equivalent — within a femtogram (1/1_000_000_000_000_000th of a gram). -
#magnitude : Float64
The numeric part of the measurement — the
1
in1.kilogram
. -
#to(unit : Unit) : self
Convert this instance to the given
Unit
. -
#to_s(io) : Nil
Output a human-readable representation of this
Weight
to the givenIO
. -
#total_grams
Returns the number of grams represented by this
Weight
instance -
#unit : Unit
The unit used in measuring the weight.
Constructor Detail
Instantiate a Weight
instance with the given #magnitude
and Unit
.
Instance Method Detail
Multiply by a scalar value
2.kg * 5
# => Measure::Length(@magnitude=10.0, @unit=Measure::Length::Unit::Kilogram)
Add two Weight
s 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)
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)
Multiply by a scalar value
10.kg / 2
# => Measure::Length(@magnitude=2.0, @unit=Measure::Length::Unit::Kilogram)
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
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.
Convert this instance to the given Unit
.
1.kilogram.to(:lbs)
# => Measure::Weight(@magnitude=2.20462, @unit=Measure::Weight::Unit::Pound)