我有以下类覆盖:
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)
没有产生错误。知道为什么吗?