From: Xavier Shay Date: 2008-10-28T16:43:26+09:00 Subject: Re: Access module's anonymous parent Pit Capitain wrote: > 2008/10/27 Xavier Shay : >> 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... > > Xavier, I don't know why you want to have an anonymous module with a > local constant Hot loading of code. I'm being a bit anal about it, also I'm just curious :) Would be nice to not need the dependent_class bit, but it's not so bad. I had to hack your code a bit to get what I want, which is this: m = Module.new m.instance_eval do self::Depend = [] def self.const_missing(name) const_set(name, Class.new) end def self.dependent_class(cls, &blk) parent_module = self (class << cls; self; end).send(:define_method, :depend) do |file| parent_module::Depend << file end cls.class_eval(&blk) end dependent_class self::A do depend("afile.rb") def foo "foo" end end end a = m.const_get('A').new puts a.foo # => foo puts m::Depend.inspect # => ["afile.rb"] Thanks! Xavier -- Posted via http://www.ruby-forum.com/.