Method: Quantify::Unit::Base#method_missing

Defined in:
lib/quantify/unit/base_unit.rb

#method_missing(method, *args, &block) ⇒ Object (private)

Provides syntactic sugar for several methods. E.g.

Unit.metre.to_kilo

is equivalent to Unit.metre.with_prefix :kilo.

Unit.m.alternatives_by_name

is equaivalent to Unit.m.alternatives :name



574
575
576
577
578
579
580
581
# File 'lib/quantify/unit/base_unit.rb', line 574

def method_missing(method, *args, &block)
  if method.to_s =~ /(to_)(.*)/ && prefix = Prefix.for($2.to_sym)
    return self.with_prefix(prefix)
  elsif method.to_s =~ /(alternatives_by_)(.*)/ && self.respond_to?($2.to_sym)
    return self.alternatives($2.to_sym)
  end
  super
end