Tuesday, January 08, 2008

obj.instance_eval and mod.module_eval(mod.class_eval) usage


class C
def initialize
@x = 1
end
end

c = C.new
c.instance_eval { puts @x }
puts c.instance_variable_get "@x"

C.class_eval do
def some_method
puts "Created in class_eval"
end
end
c = C.new
c.some_method

No comments :