Module: Phys::UnitsMixin
- Defined in:
- lib/phys/units/units_mixin.rb
Overview
Defines method with unit name. Caution: Variable names may conflict with unit names.
Class Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/phys/units/units_mixin.rb', line 41
def method_missing(method, *args, &block)
if unit=Phys::Unit.find_unit(method)
raise "argument must be empty" unless args.empty?
Phys::Quantity.new(1,method,unit)
else
method_missing_units_alias(method, *args, &block)
end
end
|
Class Method Details
.method_missing(method, *args, &block) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/phys/units/units_mixin.rb', line 41
def method_missing(method, *args, &block)
if unit=Phys::Unit.find_unit(method)
raise "argument must be empty" unless args.empty?
Phys::Quantity.new(1,method,unit)
else
method_missing_units_alias(method, *args, &block)
end
end
|
.method_missing_units_alias ⇒ Object
40
|
# File 'lib/phys/units/units_mixin.rb', line 40
alias method_missing_units_alias method_missing
|
.print_units(unit = nil) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/phys/units/units_mixin.rb', line 50
def print_units(unit=nil)
Phys::Unit::LIST.each do |k,u|
if unit.nil? || unit===u
len = 32 - k.size
len = 1 if len < 1
puts k+" "*len+"#{u.expr}"
end
end
nil
end
|