# Object.private\_instance\_methods \<--- Kernel.singleton\_metho

**URL:** <https://www.ruby-forum.com/t/object-private-instance-methods-kernel-singleton-metho/111236>\
**Category:** Ruby\
**Created:** [August 4, 2007, 4:41am UTC](https://www.ruby-forum.com/t/object-private-instance-methods-kernel-singleton-metho/111236 "2007-08-04T04:41:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronald\_braswell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f9ae1b/32.png) [@ronald\_braswell](https://www.ruby-forum.com/u/ronald_braswell)\
**Post date:** [August 4, 2007, 4:41am UTC](https://www.ruby-forum.com/t/object-private-instance-methods-kernel-singleton-metho/111236/1 "2007-08-04T04:41:38Z")

</div>

How do the Kernel.singleton\_methods get to be  
Object.private\_instance\_methods?

---

<div class="post-metadata">

**Author:** ![ronald\_braswell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f9ae1b/32.png) [@ronald\_braswell](https://www.ruby-forum.com/u/ronald_braswell)\
**Post date:** [August 4, 2007, 1:32pm UTC](https://www.ruby-forum.com/t/object-private-instance-methods-kernel-singleton-metho/111236/2 "2007-08-04T13:32:16Z")

</div>

On 8/4/07, ronald braswell [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How do the Kernel.singleton\_methods get to be  
> Object.private\_instance\_methods?  
> Are they? I do not think so, maybe you could rephrase your question, I  
> am probably missing something.

Cheers  
Robert

---

<div class="post-metadata">

**Author:** ![ronald\_braswell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f9ae1b/32.png) [@ronald\_braswell](https://www.ruby-forum.com/u/ronald_braswell)\
**Post date:** [August 4, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/object-private-instance-methods-kernel-singleton-metho/111236/3 "2007-08-04T14:24:21Z")

</div>

Hi –

On Sat, 4 Aug 2007, ronald braswell wrote:

> How do the Kernel.singleton\_methods get to be  
> Object.private\_instance\_methods?

Following the trail in eval.c and class.c, it looks like they’re bound  
to Ruby names with rb\_define\_global\_function:

```
 rb_define_global_function("raise", rb_f_raise, -1);

```

That, in turn, calls rb\_define\_module\_function for Kernel, which  
establishes the method as (a) a singleton method of Kernel itself, and  
(b) a private instance method of Kernel.

The private instance methods then trickle down. You can see them not  
only with Object but with other classes too:

Class.new.private\_instance\_methods == Object.private\_instance\_methods  
=\> true

David

---

<div class="post-metadata">

**Author:** ![ronald\_braswell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f9ae1b/32.png) [@ronald\_braswell](https://www.ruby-forum.com/u/ronald_braswell)\
**Post date:** [August 5, 2007, 6:15pm UTC](https://www.ruby-forum.com/t/object-private-instance-methods-kernel-singleton-metho/111236/4 "2007-08-05T18:15:20Z")

</div>

> am probably missing something.
> 
> Cheers  
> Robert
> 
> –  
> […] as simple as possible, but no simpler.  
> – Attributed to Albert Einstein

The question was not a good one. I now understand that the Kernel  
singleton  
methods are copies of private instance methods due to a call to  
module\_function on them. Kernel’s private instance versions of the  
methods  
get mixed in with Object as well as its public instance methods. I had  
not  
noticed that Kernel had private instance variables of the same name as  
its  
singleton methods.

Ron

---

<div class="post-metadata">

**Author:** ![ronald\_braswell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f9ae1b/32.png) [@ronald\_braswell](https://www.ruby-forum.com/u/ronald_braswell)\
**Post date:** [August 5, 2007, 6:38pm UTC](https://www.ruby-forum.com/t/object-private-instance-methods-kernel-singleton-metho/111236/5 "2007-08-05T18:38:21Z")

</div>

On 8/5/07, ronald braswell [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > How do the Kernel.singleton\_methods get to be  
> > > – Attributed to Albert Einstein
> 
> The question was not a good one. I now understand that the Kernel singleton  
> methods are copies of private instance methods due to a call to  
> module\_function on them. Kernel’s private instance versions of the methods  
> get mixed in with Object as well as its public instance methods. I had not  
> noticed that Kernel had private instance variables of the same name as its  
> singleton methods.  
> ah you meant the results, of course, I am the worst guesser of the world  
> 🙂  
> R.
