alias_method and class_methods don't mix?
Posted
by Daniel
on Stack Overflow
See other posts from Stack Overflow
or by Daniel
Published on 2010-05-27T21:19:12Z
Indexed on
2010/05/27
21:51 UTC
Read the original article
Hit count: 294
Greetings,
I've been trying to tinker with a global Cache module, but I can't figure out why this isn't working.
Does anyone have any suggestions?
This is the error produced for the below code:
NameError: undefined method get' for module
Cache'
from (irb):21:in `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
TIA!
-daniel
© Stack Overflow or respective owner