Can somebody explain me, in detail, the differences between
aModule.instance_eval, aModule.module_eval and
aModule.class_eval?
I’m especially interested in the differences in context.
There must be a difference. If I replace aModule.module_eval
with aModule.instance_eval in one spcific situation, the
results differ, although self.inspect returns the same value…
Thanks.
gegroet,
Erik V. - http://www.erikveen.dds.nl/
class Object
def metaclass
class << self
self
end
end
end
class Foo
block =
lambda do
p [self, object_id]
end
2.times do
instance_eval(&block)
module_eval(&block)
class_eval(&block)
metaclass.instance_eval(&block)
metaclass.module_eval(&block)
metaclass.class_eval(&block)
end
end
[Foo, -605291388]
[Foo, -605291388]
[Foo, -605291388]
[#Class:Foo , -605291428]
[#Class:Foo , -605291428]
[#Class:Foo , -605291428]
[Foo, -605291388]
[Foo, -605291388]
[Foo, -605291388]
[#Class:Foo , -605291428]
[#Class:Foo , -605291428]
[#Class:Foo , -605291428]