Object.private_instance_methods <--- Kernel.singleton_metho

How do the Kernel.singleton_methods get to be
Object.private_instance_methods?

On 8/4/07, ronald braswell [email protected] 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

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

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

On 8/5/07, ronald braswell [email protected] 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
:slight_smile:
R.