Class: Fixnum
- Inherits:
-
Object
- Object
- Fixnum
- Defined in:
- lib/units/base.rb
Instance Method Summary collapse
-
#*(other) ⇒ Object
Allow for scalar multiplication.
-
#+(other) ⇒ Object
Raise an error if the other number has a unit.
- #add ⇒ Object
- #multiply ⇒ Object
- #multiply_with_units(other) ⇒ Object
Instance Method Details
#*(other) ⇒ Object
Allow for scalar multiplication
150 151 152 153 154 155 156 157 |
# File 'lib/units/base.rb', line 150 def *(other) if Numeric === other && other.kind multiply_with_units other else multiply other end end |
#+(other) ⇒ Object
Raise an error if the other number has a unit
139 140 141 142 143 144 145 146 |
# File 'lib/units/base.rb', line 139 def +(other) if Numeric === other && other.kind raise UnitsError, "cannot add a number without units to one with units" else add other end end |
#add ⇒ Object
137 |
# File 'lib/units/base.rb', line 137 alias :add :+ |
#multiply ⇒ Object
148 |
# File 'lib/units/base.rb', line 148 alias :multiply :* |
#multiply_with_units(other) ⇒ Object
158 159 160 |
# File 'lib/units/base.rb', line 158 def multiply_with_units(other) multiply(other).send(unit || other.unit) end |