Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Numeric
- @@currencies = {'yen' => 0.013, 'euro' => 1.292, 'rupee' => 0.019, 'dollar' => 1}
- 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
- puts "5.euro = "+5.euro.to_s
- puts "5.euros = "+5.euros.to_s
- puts "5.dollars.in(:euros) = "+5.dollars.in(:euros).to_s
- puts "10.euros.in(:rupees) = "+10.euros.in(:rupees).to_s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement