Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Numeric
- @@currencies = {'dollar' => 1, 'yen' => 107.85, 'euro' => 0.83, 'baht' => 33.12}
- def method_missing(method, *arg)
- singular_currency = method.to_s.gsub(/s$/,'')
- if @@currencies.has_key?(singular_currency)
- self * @@currencies[singular_currency]
- else
- super
- end
- end
- def in(arg)
- singular_currency = arg.to_s.gsub(/s$/,'')
- if @@currencies.has_key?(singular_currency)
- self * @@currencies[singular_currency]
- end
- end
- end
- val = (1.dollars - 1.euro).in(:dollars)
- puts val
Advertisement
Add Comment
Please, Sign In to add comment