0
ActionController :: Base 클래스에 대해 상속 된 메서드를 구현하려고합니다. 내 목적은 ActionController :: Base에서 상속받은 클래스의 메소드를 ApplicationController와 같이 호출하여 특정 모듈을 포함하도록하는 것이다. 는 momement에서 내 코드는 다음과 같습니다레일즈 2.3.11에서 ActionController :: Base 클래스에 상속 된 후크를 정의 할 수 있습니까?
module MyModule
def inherited(child)
end
def my_test_method()
end
end
ActionController::Base.send(:extend, MyModule)
ActionController::Base.methods.include? 'my_test_method'
=> true
ActionController::Base.methods.include? 'inherited'
=> false
코드는 플러그인의 init 파일에서라고합니다.
안녕하세요 론을 클래스에 classmethod를 추가하여 모듈로 확장 할 수 있다는 것을 알고 있습니다. 내 예제에 따르면 'my_test_method'의 경우 작동합니다. 그런데 왜 상속 된 메서드로 작동하지 않습니까? ActiveRecord :: Base와 같은 다른 클래스에서 시도해 보았습니다. –
필자는 왜 덮어 쓰기가 작동하고 확장하는지 알지 못합니다. – L0ne