alias_method e class_methods não se misturam?
Eu tenho tentado mexer com um módulo de cache global, mas não consigo descobrir por que isso não está funcionando.
Alguém tem alguma sugestão?
Este é o erro:
NameError: undefined method `get' for module `Cache'
from (irb):21:in `alias_method'
... gerado por este código:
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