Why can’t I refer to constants nested inside a class within a module eval?
irb(main):001:0> class A
irb(main):002:1> class B
irb(main):003:2> end
irb(main):004:1> end
=> nil
irb(main):005:0> A.module_eval { puts B }
NameError: uninitialized constant B
from (irb):5
from (irb):5:in `module_eval'
from (irb):5
from :0
This is frustrating. Can anyone explain why it has to be this way? Perhaps there’s a good reason I’m not considering.
About the Author