G
Gaspard Bucher
I need to eval code that will create globally available classes. I tried this :
class Test
def makeA
Module.sendeval, "class A; end")
# same with: eval "class A; end"
puts Test.const_get('A') # => Test::A
puts Module.const_get('A') # => raise NameError, why ?
end
end
eval "class B; end"
puts Module.const_get('B') # => B
Test.new.makeA #=> bang
Thanks for your help.
Gaspard
class Test
def makeA
Module.sendeval, "class A; end")
# same with: eval "class A; end"
puts Test.const_get('A') # => Test::A
puts Module.const_get('A') # => raise NameError, why ?
end
end
eval "class B; end"
puts Module.const_get('B') # => B
Test.new.makeA #=> bang
Thanks for your help.
Gaspard