我想要寫在Ruby中一個基類,可以擴展它的回調登記類,多ApplicationController中不與的before_filter方式:Ruby的基類,允許其子類註冊爲回調
class AController < ApplicationController
before_filter :foo
def foo
end
end
我想自己寫一些類似before_filter的另一面。
class AClass < MyBase
register_callback :callback1
def callback1
puts "called!"
end
def test
call_me_maybe 5
end
end
的call_me_maybe
方法在MyBase
類中定義,並可能調用先前已註冊的回調。 MyBase的實現是什麼樣的。