From: ts Date: 2001-12-28T15:56:04+09:00 Subject: [ruby-talk:29514] Re: Module#included >>>>> "B" == Bob Hutchison writes: Well, the response was given by Nobu Nakada. Just a small example B> Is there a recommended way to obtain some data from the new module (the one B> including this module). For example, I'd like to set up a hash that maps a B> string to the new module, but only if it is defined. The trouble is that I B> cannot use the included module to define default values (it seems, and this B> is why I think the method is called before the module is included). I am B> forced to trap an exception if the string is not defined in the new module B> -- this works, but... Here a stupid example which define an instance variable (if it's not defined) in the class which make the include pigeon% cat b.rb #!./ruby module M def self.included klass klass.class_eval do @data ||= M class << self attr_reader :data end end end end class C include M end p C.data class D @data = C include M end p D.data pigeon% pigeon% b.rb M C pigeon% B> What can you do in the included method? Can you affect how things are B> included? or is this simply an interesting event? Like it was said previously ::included is called after ::append_features. I'll say that ::append_features can affect how things are included ::included is an interesting event that you can use after the include is made. Guy Decoux