我有下面的类覆盖:红宝石 - 引发ArgumentError:错误的参数数目(2 1)
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
每当在参数是复数,例如:10.dollars.in(:yens)
我得到ArgumentError: wrong number of arguments (2 for 1)
但10.dollars.in(:yen)
产生任何错误。任何想法为什么?
这个问题是题外话,因为它们只会让我们关闭错字/语法相关的问题这样 – random 2013-07-07 12:44:27