Where is instance_eval() defined?

Where in the hell is instance_eval() defined? In “The Ruby P.ming
Language”, it says it’s defined in Object, but the 1.9.2 docs don’t list
it in Object:

http://www.ruby-doc.org/core/classes/Object.html

Nor is it listed in BasicObjec, Kernel, Module, or Class:

http://www.ruby-doc.org/core-1.9/classes/BasicObject.html
http://www.ruby-doc.org/core/classes/Kernel.html
http://ruby-doc.org/core/classes/Module.html
http://www.ruby-doc.org/core/classes/Class.html

On Wed, May 18, 2011 at 11:10 PM, 7stud – [email protected]
wrote:

Where in the hell is instance_eval() defined? In “The Ruby P.ming
Language”, it says it’s defined in Object, but the 1.9.2 docs don’t list
it in Object:

irb --simple-prompt

require “pp”
pp Object.methods.sort


Phillip G.

Though the folk I have met,
(Ah, how soon!) they forget
When I’ve moved on to some other place,
There may be one or two,
When I’ve played and passed through,
Who’ll remember my song or my face.

Thanks. Does anyone want to fix that in the 1.9.2 docs?

Also, I can never find the methods() method anywhere. Module?
BasicObject?

7stud – wrote in post #999537:

Nor is it listed in BasicObjec

p RUBY_VERSION # => “1.9.2”
p BasicObject.public_instance_methods.grep(/eval/) # => [:instance_eval]

and in vm_eval.c:

rb_define_method(rb_cBasicObject, “instance_eval”, rb_obj_instance_eval,
-1);

In future do this:

method(:instance_eval).owner #=> BasicObject

And you can use pry to find sourcecode and sourcefile information:

pry(main)> show-method instance_eval

From: vm_eval.c in Ruby Core (C Method):
Number of lines: 13

VALUE
rb_obj_instance_eval(int argc, VALUE *argv, VALUE self)
{
VALUE klass;

if (SPECIAL_CONST_P(self)) {
klass = Qnil;
}
else {
klass = rb_singleton_class(self);
}
return specific_eval(argc, argv, klass, self);

}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs