Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Numeric
- @@currencies = {'dollar' => 1.0, 'yen' => 0.0093, 'euro' => 1.204, 'rupee' => 0.019, 'baht' => 0.03}
- def method_missing(method_id, *args, &block)
- if method_id == :in
- convert_to = args[0].to_s.gsub( /s$/, '')
- if @@currencies.has_key?(convert_to)
- self / @@currencies[convert_to]
- else
- super
- end
- else
- singular_currency = method_id.to_s.gsub( /s$/, '')
- if @@currencies.has_key?(singular_currency)
- self * @@currencies[singular_currency]
- else
- super
- end
- end
- end
- end
- val = (3.dollars).in(:baht)
- puts val
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement