Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/stick/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



954
955
956
957
958
959
960
961
962
963
964
965
# File 'lib/stick/units/base.rb', line 954

def method_missing(m, *args, &blk)
  if args.length == 1
    args[0] = (Stick::Units::Converter.converter(args[0]) rescue nil) if not args[0].is_a?(Stick::Units::Converter)
    return Stick::Units::Value.new(self, Stick::Units::Unit.new({m => 1}, args[0])) if args[0] && args[0].registered?(m)
  elsif Stick::Units::Converter.current.registered?(m)
    raise ::ArgumentError, "Wrong number of arguments" if args.length != 0
    return Stick::Units::Value.new(self, Stick::Units::Unit.new({m => 1}, Stick::Units::Converter.current))
  end
  ::Exception.with_clean_backtrace("method_missing") {
    super
  }
end

Instance Method Details

#to_value(unit) ⇒ Object



968
969
970
# File 'lib/stick/units/base.rb', line 968

def to_value(unit)
  Stick::Units::Value.new(self, unit)
end