Method: Quantify::Unit::Base#pow
- Defined in:
- lib/quantify/unit/base_unit.rb
#pow(power) ⇒ Object Also known as: **
Raise a unit to a power. This results in the generation of a compound unit, e.g. m^3.
In the event that the new unit represents a known unit, the non-compound representation is returned (i.e. of the SI or NonSI class).
478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/quantify/unit/base_unit.rb', line 478 def pow(power) return nil if power == 0 original_unit = self.clone if power > 0 new_unit = self.clone (power - 1).times { new_unit *= original_unit } elsif power < 0 new_unit = reciprocalize ((power.abs) - 1).times { new_unit /= original_unit } end return new_unit end |