From: Yukihiro Matsumoto Date: 2006-05-23T16:23:23+09:00 Subject: Re: module creation hook method (Re: [OT] Re: initializing instance variables in a module) Hi, In message "Re: module creation hook method (Re: [OT] Re: initializing instance variables in a module)" on Tue, 23 May 2006 15:35:30 +0900, ara.t.howard@noaa.gov writes: | harp:~ > cat a.rb | class Class | WRAPPER = [] | def inherited other | wrapper = WRAPPER.first | wrapper.const_set other.name.split(%r/::/).last, other if wrapper | end | def load file, m | wrapping(m){ ::Kernel.load file, wrap = true } | end | def wrapping m | WRAPPER.push m | yield | ensure | WRAPPER.pop | end | end | | m = Module.new | | Class.load 'b.rb', m | | p m::C | p C |i'd like to do the same for modules. Thank you for the example. I am still not sure this is a right tool for the right purpose, but I do understand what you wanted to do in the code. Hidetoshi NAGAI is proposing load_to(file, module) method to do the thing you wanted. In my opinion, this is better way to implement. | how about #inherited then? | | harp:~ > ruby -e' p Module.new.is_a?(Module) ' | true I am not positive for this one. Since this is misleading people to feel like modules are inherited from something. | or perhaps #defined | or perhaps #created Maybe. Much better than inherited. Or maybe invoking initialize at the module creation is even better. matz.