From: Xavier Shay Date: 2008-10-28T06:54:26+09:00 Subject: Re: Access module's anonymous parent Brian Candler wrote: > Is this what you're looking for? > > m = Module.new > m.instance_eval do > def foo > puts "Foo called" > end > parent = self > child = class self::A; self; end > child.class_eval { parent.foo } > end > a = m.const_get('A').new > puts ParentSelf # This should raise - constant should not exist > > (you can also use 'm.foo' instead of 'parent.foo', which means you can > remove the assignment 'parent = self') I would have liked to keep the more familiar class syntax without resorting to class_eval > parent = self > child = class self::A; self; end > child.class_eval { parent.foo } I'm autoloading a file, it contains this part, so it's basically the public interface. > class self::A > parent.foo And for that reason this is a much nicer, I think. But if it can't be done like this, it can't be done... -- Posted via http://www.ruby-forum.com/.