From: Xavier Shay Date: 2008-10-27T17:15:17+09:00 Subject: Access module's anonymous parent I want the following eval to output "Foo called", without having a named constant, since in leaks in to the calling scope: m = Module.new m.instance_eval do def foo puts "Foo called" end ParentSelf = self class self::A ParentSelf.foo # How do I do this without a constant? end end a = m.const_get('A').new puts ParentSelf # This should raise - constant should not exist I have found given self and a global function, I can use the string representation of the anon module to find it in ObjectSpace. Clearly this is dodgy though: def depend(instance, file) q = self.to_s.split('::').first.to_s found = nil ObjectSpace.each_object(Module) do |m| found = m if q == m.to_s end found.depend(file) end m = Module.new m.instance_eval do def depend(file) puts "Depend called with file: #{file}" end class self::A depend(self, 'afile.rb') end end -- Posted via http://www.ruby-forum.com/.