Created
March 12, 2012 13:22
-
-
Save anonymous/2021880 to your computer and use it in GitHub Desktop.
This file contains 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 = {'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) #has_key checks whether or not that key is present in preceeding hash. | |
self * @@currencies[singular_currency] | |
else | |
super | |
end | |
end | |
end | |
p 1000.rupees | |
=begin | |
I want something like 5.dollars.in(:euros) and 10.euros.in(:rupees) to work | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment