From: Calamitas Date: 2009-03-18T09:08:32+09:00 Subject: Re: Dynamically extending modules once they have been included On Tue, Mar 17, 2009 at 1:12 AM, wrote: > The only alternative I've find is to loop through the ObjectSpace > (filtering on classes) and find out which class's ancestors include > the module I want to extend and then include my extension module > straight into the class. Below is code taken from my FOSDEM presentation. It tries to tackle the problem you are describing. It is not well-tested or anything, but it did pass the examples I used in the presentation. Just execute this code before any of your module definitions and see if it helps. Peter class Module def included_in @included_in ||= {} end def included(m) unless included_in[m] included_in[m] = true m.update_inclusions end end def extended(m) included(class << m ; self ; end) end def update_inclusions included_in.each do |m, _| m.send(:include, self) m.update_inclusions end end end