Method: Quantify::Unit::Base#coerce
- Defined in:
- lib/quantify/unit/base_unit.rb
#coerce(object) ⇒ Object
Enables shorthand for reciprocal of a unit, e.g.
unit = Unit.m
(1/unit).symbol #=> "m^-1"
529 530 531 532 533 534 535 |
# File 'lib/quantify/unit/base_unit.rb', line 529 def coerce(object) if object.kind_of?(Numeric) && object == 1 return Unit.unity, self else raise Exceptions::InvalidArgumentError, "Cannot coerce #{self.class} into #{object.class}" end end |