Module: Phys::UnitsNumericMixin
- Included in:
- Quantity
- Defined in:
- lib/phys/units/units_mixin.rb
Overview
ActiveSupport-like mix-in. Caution: This kind of global change will cause unexpected problems.
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# 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
|
Instance Method Details
#call(unit) ⇒ Object
97
98
99
|
# File 'lib/phys/units/units_mixin.rb', line 97
def call(unit)
self * unit
end
|
#method_missing_units_alias ⇒ Object