Module: Phys::UnitsNumericMixin

Defined in:
lib/phys/units/units_mixin.rb

Overview

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

Examples:

require 'phys/units'

class Numeric
  include Phys::UnitsNumericMixin
end

1.miles/1.hr >> 'm/s'  #=> Phys::Quantity[0.44704,"m/s"]

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


74
75
76
77
78
79
80
81
# File 'lib/phys/units/units_mixin.rb', line 74

def method_missing(method, *args, &block)
  if unit=Phys::Unit.find_unit(method)
    raise "argument must be empty" unless args.empty?
    Phys::Quantity.new(self,method,unit)
  else
    method_missing_units_alias(method, *args, &block)
  end
end

Instance Method Details

#method_missing_units_aliasObject


73
# File 'lib/phys/units/units_mixin.rb', line 73

alias method_missing_units_alias method_missing