我有下面的類覆蓋:紅寶石 - 引發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