Class: Numeric
- Inherits:
-
Object
show all
- Defined in:
- lib/van/units/base.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &blk) ⇒ Object
961
962
963
964
965
966
967
968
969
970
971
972
|
# File 'lib/van/units/base.rb', line 961
def method_missing(m, *args, &blk)
if args.length == 1
args[0] = (Van::Units::Converter.converter(args[0]) rescue nil) if not args[0].is_a?(Van::Units::Converter)
return Van::Units::Value.new(self, Van::Units::Unit.new({m => 1}, args[0])) if args[0] && args[0].registered?(m)
elsif Van::Units::Converter.current.registered?(m)
raise ::ArgumentError, "Wrong number of arguments" if args.length != 0
return Van::Units::Value.new(self, Van::Units::Unit.new({m => 1}, Van::Units::Converter.current))
end
::Exception.with_clean_backtrace("method_missing") {
super
}
end
|
Instance Method Details
#to_value(unit) ⇒ Object
975
976
977
|
# File 'lib/van/units/base.rb', line 975
def to_value(unit)
Van::Units::Value.new(self, unit)
end
|