On Aug 29, 2006, at 4:57 AM, Mauricio Fernandez wrote: > On Tue, Aug 29, 2006 at 05:36:39PM +0900, Robert Dober wrote: >> On 8/29/06, Mauricio Fernandez <mfp / acm.org> wrote: >>> The above code effectively removes inherited methods too (as well >>> as those >>> from other modules that were included previously): > [...] >>> Here's another way to do it without clobbering inherited methods; >>> the >>> key difference is that the original module will not be added to the >>> inheritance chain: > [...] >> >> Brilliant, the is_a? relation should not hold anyway after a partial >> include, that was kind of where I blocked. > > Right, since is_a? doesn't hold anymore, you cannot add methods to > the module > either, e.g. > > module B; def foo; "B#foo" end end > class X; append_from B, :foo end > module B; def bar; "B#bar" end end > > X.new.bar # ====> would raise a NoMethodError > > ... and you cannot capture new methods in B.method_added since Ruby > won't let > you rebind them. But that's OK, since we wanted *only* the methods > explicitly > passed to #append_from to be imported. In fact, you'd have to add > some code > (similar to BlankSlate's) to the other solution (the one with a > "child module" > and #undef_method) to handle this correctly (and it'd still suffer > from the > method shadowing/clobbering problem). > Yeah I knew it would clobber the old methods, but I couldn't think of a way to do it w/o clobbering them. Silly me not thinking of clone. (My original attempt want to use UboundMethod#to_proc + define_method (IMO being closest to the desired behavior), unfortunately there is no such thing as UnboundMethod#to_proc. > -- > Mauricio Fernandez - http://eigenclass.org - singular Ruby >