alias_method from singleton_method_added

A

Aaron Baldwin

I'm trying to alias a method at the point that method is defined.
Here is an example that results in the error: NameError: undefined
method 'foo' for class `Test'.

class Test
class << self
def singleton_method_added(m)
puts m
alias_method :bar, :foo
end

def foo
end
end
end

How can I call alias_method from within singleton_method_added and
access the singleton method?

Thanks,
Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top