Skip to content

Instantly share code, notes, and snippets.

@shanab
Last active August 29, 2015 14:06
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/43e4e1e219cd59545914 to your computer and use it in GitHub Desktop.
Save shanab/43e4e1e219cd59545914 to your computer and use it in GitHub Desktop.
Extending Numeric class to add currencies
class Numeric
@@currencies = { dollar: 7.15, euro: 9.26, yen: 0.068 }
@@currencies.each do |currency, rate|
define_method(currency) do
self * rate
end
alias_method "#{currency}s".to_sym, currency
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment