13
나는 글로벌 캐시 모듈을 고치려고 노력했지만, 왜 이것이 작동하지 않는지 알 수 없다.alias_method와 class_methods가 섞이지 않습니까?
누구에게 의견이 있습니까?
NameError: undefined method `get' for module `Cache'
from (irb):21:in `alias_method'
...이 코드에 의해 생성 : alias_method
에
module Cache
def self.get
puts "original"
end
end
module Cache
def self.get_modified
puts "New get"
end
end
def peek_a_boo
Cache.module_eval do
# make :get_not_modified
alias_method :get_not_modified, :get
alias_method :get, :get_modified
end
Cache.get
Cache.module_eval do
alias_method :get, :get_not_modified
end
end
# test first round
peek_a_boo
# test second round
peek_a_boo
을 <
Chuck
@Chuck, 좋은 지적; 업데이트되었습니다! – molf