私は次のクラスを上書きしています:
class Numeric
@@currencies = {:dollar => 1, :yen => 0.013, :euro => 1.292, :rupee => 0.019}
def method_missing(method_id)
singular_currency = method_id.to_s.gsub( /s$/, '').to_sym
if @@currencies.has_key?(singular_currency)
self * @@currencies[singular_currency]
else
super
end
end
def in(destination_currency)
destination_curreny = destination_currency.to_s.gsub(/s$/, '').to_sym
if @@currencies.has_key?(destination_currency)
self / @@currencies[destination_currency]
else
super
end
end
end
たとえば、 in の引数が複数形の場合は常に、10.dollars.in(:yens)
取得しますArgumentError: wrong number of arguments (2 for 1)
が10.dollars.in(:yen)
エラーは発生しません。理由はありますか?