Skip to content

Instantly share code, notes, and snippets.

Created April 14, 2013 03:10
Show Gist options
  • Save anonymous/3487b717292dbaa54d5c to your computer and use it in GitHub Desktop.
Save anonymous/3487b717292dbaa54d5c to your computer and use it in GitHub Desktop.
class Numeric
@@currencies = {'yen' => 0.013, 'euro' => 1.292, 'rupee' => 0.019}
def method_missing(method_id)
singular_currency = method_id.to_s.gsub( /s$/, '')
if @@currencies.has_key?(singular_currency)
self * @@currencies[singular_currency]
else
super
end
end
def in(curSymbol)
if (curSymbol.class == Symbol)
singularCurrencyString = curSymbol.to_s.gsub(/s$/, '')
if @@currencies.has_key?(singularCurrencyString)
self * 1 / (@@currencies[singularCurrencyString])
elsif (singularCurrencyString == 'dollar')
return self
else
super
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment