Christopher J. Bottaro
7/11/2008 3:18:00 PM
I was looking at someone's implementation of #meta_eval and I noticed
they used #instance_eval. I've always been using #class_eval with
metaclasses and getting my desired effect. So why use #instance_eval
over #class_eval when working with metaclasses?
Furthermore, I can't even tell a difference, as demonstrated by this
code snippet.
class Object
def metaclass
class << self
self
end
end
end
class Test
def f
metaclass.class_eval do
puts self.inspect
end
end
def g
metaclass.instance_eval do
puts self.inspect
end
end
end
t = Test.new
t.f
t.g
#<Class:#<Test:0x8eae4>>
#<Class:#<Test:0x8eae4>>
Using #class_eval and #instance_eval both produce the same result.
Can anyone shed some light on this subject?
Thanks.