Object.private_instance_methods <--- Kernel.singleton_methods

  • Thread starter ronald braswell
  • Start date
R

Robert Dober

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
 
D

dblack

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

--
* 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)
 
R

Robert Dober

The question was not a good one. I now understand that the Kernel single= ton
methods are copies of private instance methods due to a call to
module_function on them. Kernel's private instance versions of the meth= ods
get mixed in with Object as well as its public instance methods. I had n= ot
noticed that Kernel had private instance variables of the same name as it= s
singleton methods.
ah you meant the results, of course, I am the worst guesser of the world :)
R.
Ron

_________________________________________________________________
More photos, more messages, more storage=97get 2GB with Windows Live Hotm= ail.
igration_HM_mini_2G_0507


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,318
Members
47,998
Latest member
GretaCjy4

Latest Threads

Top