Class: Fixnum

Inherits:
Object
  • Object
show all
Defined in:
lib/cooking.rb

Instance Method Summary collapse

Instance Method Details

#*(other) ⇒ Object

Allow for scalar multiplication



150
151
152
153
154
155
156
157
# File 'lib/cooking.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/cooking.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

#addObject



137
# File 'lib/cooking.rb', line 137

alias :add :+

#multiplyObject



148
# File 'lib/cooking.rb', line 148

alias :multiply :*

#multiply_with_units(other) ⇒ Object



158
159
160
# File 'lib/cooking.rb', line 158

def multiply_with_units(other)
  multiply(other).send(unit || other.unit)
end