Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/unitwise/ext/numeric.rb
Instance Method Summary collapse
-
#convert_to(unit) ⇒ Unitwise::Measurement
Converts numeric to a measurement.
-
#method_missing(meth, *args, &block) ⇒ Object
Converts numeric to a measurement by the method name.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
Converts numeric to a measurement by the method name
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/unitwise/ext/numeric.rb', line 17 def method_missing(meth, *args, &block) if args.empty? && !block_given? unit = (match = /\Ato_(\w+)\Z/.match(meth.to_s)) ? match[1] : meth begin convert_to(unit) rescue Unitwise::ExpressionError super(meth, *args, &block) end else super(meth, *args, &block) end end |
Instance Method Details
#convert_to(unit) ⇒ Unitwise::Measurement
Converts numeric to a measurement
8 9 10 |
# File 'lib/unitwise/ext/numeric.rb', line 8 def convert_to(unit) Unitwise::Measurement.new(self, unit) end |