Module: UnitMeasurements::Conversion
- Included in:
- Measurement
- Defined in:
- lib/unit_measurements/conversion.rb
Overview
The UnitMeasurements::Conversion
mixin module defines methods for converting quantity of the measurement to various numeric types. These methods allow for flexibility in handling measurements in different numeric formats.
This module is included into the Measurement
class to allow conversion of the measurement quantity to other numeric types.
Instance Method Summary collapse
-
#to_c ⇒ Measurement
Converts quantity of the measurement to
Complex
. -
#to_d ⇒ Measurement
Converts quantity of the measurement to
BigDecimal
. -
#to_f ⇒ Measurement
Converts quantity of the measurement to
Float
. -
#to_i ⇒ Measurement
Converts quantity of the measurement to
Integer
. -
#to_r ⇒ Measurement
Converts quantity of the measurement to
Rational
.
Instance Method Details
#to_c ⇒ Measurement
Converts quantity of the measurement to Complex
.
73 74 75 |
# File 'lib/unit_measurements/conversion.rb', line 73 def to_c self.class.new(quantity.to_c, unit) end |
#to_d ⇒ Measurement
Converts quantity of the measurement to BigDecimal
.
88 89 90 |
# File 'lib/unit_measurements/conversion.rb', line 88 def to_d self.class.new(quantity.to_d, unit) end |
#to_f ⇒ Measurement
Converts quantity of the measurement to Float
.
43 44 45 |
# File 'lib/unit_measurements/conversion.rb', line 43 def to_f self.class.new(quantity.to_f, unit) end |
#to_i ⇒ Measurement
Converts quantity of the measurement to Integer
.
28 29 30 |
# File 'lib/unit_measurements/conversion.rb', line 28 def to_i self.class.new(quantity.to_i, unit) end |
#to_r ⇒ Measurement
Converts quantity of the measurement to Rational
.
58 59 60 |
# File 'lib/unit_measurements/conversion.rb', line 58 def to_r self.class.new(quantity.to_r, unit) end |