# Alias\_method from singleton\_method\_added

**URL:** <https://www.ruby-forum.com/t/alias-method-from-singleton-method-added/128336>\
**Category:** Ruby\
**Created:** [February 6, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/alias-method-from-singleton-method-added/128336 "2008-02-06T21:40:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ambrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d9b06d/32.png) [@ambrice](https://www.ruby-forum.com/u/ambrice)\
**Post date:** [February 6, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/alias-method-from-singleton-method-added/128336/1 "2008-02-06T21:40:09Z")

</div>

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
