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