module Phys::UnitsNumericMixin

ActiveSupport-like mix-in. Caution: This kind of global change will cause unexpected problems. @example

require 'phys/units'

class Numeric
  include Phys::UnitsNumericMixin
end

1.miles/hr >> m/s     #=> Phys::Quantity[0.44704,"m/s"]
1.(km/s) >> miles/hr  #=> Phys::Quantity[(1/0.00044704),"miles/hr"]

Public Instance Methods

call(unit) click to toggle source
# File lib/phys/units/units_mixin.rb, line 97
def call(unit)
  self * unit
end
method_missing(method, *args, &block) click to toggle source
# File lib/phys/units/units_mixin.rb, line 81
def method_missing(method, *args, &block)
  if unit = Unit.find_unit(method)
    raise "argument must be empty" unless args.empty?
    case self
    when Integer
      Quantity.new(Rational(self), method, unit)
    when Numeric
      Quantity.new(self, method, unit)
    else
      self * Quantity.new(1, method, unit)
    end
  else
    method_missing_units_alias(method, *args, &block)
  end
end
Also aliased as: method_missing_units_alias
method_missing_units_alias(method, *args, &block)
Alias for: method_missing