Alias_method from singleton_method_added

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs