X
Xavier Shay
How can I enumerate all the constants inside the module in the second
example?
Notice that #constants array is empty
For bonus points, which is the "correct" eval method to use to define a
class inside the module (they all seem to work)
Cheers,
Xavier
module Foo
class A
end
end
puts Foo.constants.inspect # => ["A"]
[:module_eval, :instance_eval, :class_eval].each do |method|
m = Module.new
m.send(method) do
class B
end
end
puts m.constants.inspect # => [] (I would expect ['B'])
puts m.const_get('B').inspect # => B
end
example?
Notice that #constants array is empty
For bonus points, which is the "correct" eval method to use to define a
class inside the module (they all seem to work)
Cheers,
Xavier
module Foo
class A
end
end
puts Foo.constants.inspect # => ["A"]
[:module_eval, :instance_eval, :class_eval].each do |method|
m = Module.new
m.send(method) do
class B
end
end
puts m.constants.inspect # => [] (I would expect ['B'])
puts m.const_get('B').inspect # => B
end