可能重複:
When monkey patching a method, can you call the overridden method from the new implementation?通過覆蓋的方法添加功能,但還是把原來的方法
所以我想簡單地通過重寫它的一些條件檢查添加的方法,但後來我想要調用原始方法。一個人如何做到這一點在紅寶石?
即。
方法存在
def fakeMethod(cmd)
puts "#{cmd}"
end
,我想補充
if (cmd) == "bla"
puts "caught cmd"
else
fakeMethod(cmd)
end
任何想法?
這是[當猴子打補丁的方法,你可以在新的實現中調用重寫的方法]的副本(http://stackoverflow.com/a/4471202/2988)。 –