Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # metaprogramming to the rescue!
- class Numeric
- @@currencies = {'yen' => 0.013, 'euro' => 1.292, 'rupee' => 0.019, 'auksinas' => 10.09 }
- def method_missing(method_id, *args, &block) # capture all args in case have to call super
- singular_currency = method_id.to_s.gsub( /s$/, '')
- singular_currency_s = method_id.to_s.gsub( /es$/, '')
- if @@currencies.has_key?(method_id)
- self * @@currencies[method_id]
- elsif @@currencies.has_key?(singular_currency)
- self * @@currencies[singular_currency]
- elsif @@currencies.has_key?(singular_currency_s)
- self * @@currencies[singular_currency_s]
- else
- super
- end
- end
- end
Add Comment
Please, Sign In to add comment