Created
September 5, 2014 21:48
-
-
Save shanab/219139502f117d362fab to your computer and use it in GitHub Desktop.
Extending Numeric class to add currencies using method_missing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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