Object.private_instance_methods <--- Kernel.singleton_methods

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

···

_________________________________________________________________
A new home for Mom, no cleanup required. All starts here. http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us

Are they? I do not think so, maybe you could rephrase your question, I
am probably missing something.

Cheers
Robert

···

On 8/4/07, ronald braswell <rpbraswell@hotmail.com> wrote:

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

--
[...] as simple as possible, but no simpler.
-- Attributed to Albert Einstein

Hi --

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

···

On Sat, 4 Aug 2007, ronald braswell wrote:

--
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242\)
   RUBY FOR RAILS (http://www.manning.com/black\)
* Ruby/Rails training
     & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)

From: "Robert Dober" <robert.dober@gmail.com>
Reply-To: ruby-talk@ruby-lang.org
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subject: Re: Object.private_instance_methods <--- Kernel.singleton_methods
Date: Sat, 4 Aug 2007 20:30:10 +0900

> 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

--
[...] 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/4/07, ronald braswell <rpbraswell@hotmail.com> wrote:

_________________________________________________________________
More photos, more messages, more storage—get 2GB with Windows Live Hotmail. http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507

>From: "Robert Dober" <robert.dober@gmail.com>
>Reply-To: ruby-talk@ruby-lang.org
>To: ruby-talk@ruby-lang.org (ruby-talk ML)
>Subject: Re: Object.private_instance_methods <--- Kernel.singleton_methods
>Date: Sat, 4 Aug 2007 20:30:10 +0900
>
> > 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
>
>
>--
>[...] 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.

ah you meant the results, of course, I am the worst guesser of the world :slight_smile:
R.

···

On 8/5/07, ronald braswell <rpbraswell@hotmail.com> wrote:

>On 8/4/07, ronald braswell <rpbraswell@hotmail.com> wrote:

Ron

_________________________________________________________________
More photos, more messages, more storage—get 2GB with Windows Live Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507

--
[...] as simple as possible, but no simpler.
-- Attributed to Albert Einstein