# Fwd: Top level methods are becoming singleton method as well as instance method - Why?

**URL:** <https://www.ruby-forum.com/t/fwd-top-level-methods-are-becoming-singleton-method-as-well-as-instance-method-why/232984>\
**Category:** Ruby\
**Created:** [November 8, 2014, 2:51pm UTC](https://www.ruby-forum.com/t/fwd-top-level-methods-are-becoming-singleton-method-as-well-as-instance-method-why/232984 "2014-11-08T14:51:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [November 8, 2014, 2:51pm UTC](https://www.ruby-forum.com/t/fwd-top-level-methods-are-becoming-singleton-method-as-well-as-instance-method-why/232984/1 "2014-11-08T14:51:49Z")

</div>

Apparently the last message did not go to the list.

---------- Forwarded message ----------  
From: Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Fri, Nov 7, 2014 at 10:48 PM  
Subject: Re: Top level methods are becoming singleton method as well  
as instance method - Why ?  
To: Arup R.

On Fri, Nov 7, 2014 at 6:24 PM, Arup R.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > NoMethodError: private method `a' called for #<Object:0x007f8c5a150430> from (irb):4 from /Users/shreyas/.rvm/rubies/ruby-2.1.4/bin/irb:11:in `’
> > > 
> > > > > Object.new.send(:a)
> > > 
> > > =\> 10
> > 
> > Your test does not prove anything about a singleton method because it  
> > does not show where the method is defined.

> > > Foo.bar  
> > > But in case main posted example, Object.new.a and Object.a both work. Which  
> > > made me confused. I don’t know why… ☹

Because

$ ruby -e ‘p self, self.class’  
main  
Object

and because

$ ruby -e ‘def a;end;p method(:a)’  
#\<Method: Object#a\>

and because

$ ruby -e ‘p Object.singleton\_class.ancestors’  
[Class, Module, Object, Kernel, BasicObject]

In other words:

Object.new.a tries to invoke the instance method of Object. Easy.

Object.a invokes an instance method of singleton class of Object. That  
singleton class inherits Object and thus all instance methods from  
Object.

Yes, there is some self-referentiality. But one can get used to it.

Kind regards

robert
