fork download
  1. class Numeric
  2. @@currencies = {'dollar' => 1, 'yen' => 0.013, 'euro' => 1.292, 'rupee' => 0.019}
  3. def method_missing(method_id, *args)
  4. if method_id == "in"
  5. singular_currency = args.to_s.gsub( /s$/, '')
  6. if @@currencies.has_key?(singular_currency)
  7. self * @@currencies[singular_currency]
  8. end
  9. end
  10.  
  11. singular_currency = method_id.to_s.gsub( /s$/, '')
  12. if @@currencies.has_key?(singular_currency)
  13. self / @@currencies[singular_currency]
  14. else
  15. super
  16. end
  17. end
  18. end
  19.  
  20. print 3.dollar.in(:dollar)
Runtime error #stdin #stdout 0s 4760KB
stdin
Standard input is empty
stdout
Standard output is empty