From: nobu.nokada@... Date: 2001-12-28T08:59:24+09:00 Subject: [ruby-talk:29492] Re: Module#included Hi, At Fri, 28 Dec 2001 06:24:12 +0900, Bob Hutchison wrote: > It takes one argument that I know of, the new module that is including this > module. Are there other arguments? (I don't think so, guessing from the call > to rb_define_private_method in object.c -- the last argument is 1 which is > called argc in the method's definition in class.c). Nothing more. > When is this called? before or after the method is included? what is the > state of the module being defined when this method is called? I think it is > called before the module is included. After Module#append_features. > Is there a recommended way to obtain some data from the new module (the one > including this module). For example, I'd like to set up a hash that maps a > string to the new module, but only if it is defined. The trouble is that I > cannot use the included module to define default values (it seems, and this > is why I think the method is called before the module is included). I am > forced to trap an exception if the string is not defined in the new module > -- this works, but... The argument passed to Module#included is the new module itself. $ cat tmp.rb module M def M.included(c) puts "M included by #{c}" c.new.m # works already end def m puts self end end class C include M end $ ruby tmp.rb M included by C # Nobu Nakada