Skip to content

Instantly share code, notes, and snippets.

@shanab
Created September 5, 2014 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanab/219139502f117d362fab to your computer and use it in GitHub Desktop.
Save shanab/219139502f117d362fab to your computer and use it in GitHub Desktop.
Extending Numeric class to add currencies using method_missing
class Numeric
@@currencies = { dollar: 7.15, euro: 9.26, yen: 0.068 }
def method_missing(method_id, *args, &block)
singular_currency = method_id.to_s.gsub(/s$/, '').to_sym
if @@currencies.has_key?(singular_currency)
self * @@currencies[singular_currency]
else
super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment