1
모듈을 alias_method_chain
에 포함시키려는 모듈을 원합니다. 여기에 내가 쓴 방법입니다alias_method_chain in module
module MyModule
self.included(base)
base.class_eval do
alias_method_chain :perform, :chain
end
end
def perform_with_chain(opts)
#Do some stuffs
perform_without_chain(opts)
#Do some other stuffs
end
end
class SomeClass
include MyModule
def perform(opts)
end
end
을하지만이 모듈이 포함되어있는 경우에는 perform
방법은 아직 SomeClass
에 정의되지 않은, 때문에 오류가 발생합니다 하나는이 패턴을 작성해야하는 방법
in `alias_method': undefined method `perform' for class `SomeClass' (NameError)
을 별칭 체인이 완벽하게 작동합니까?
일부 사용자는 모듈을 어디에 포함할지주의해야합니다. 더 나은 해결책이 있습니까? –