From: Ross Bamford Date: 2006-03-10T22:42:40+09:00 Subject: Re: unextend ? On Fri, 2006-03-10 at 01:03 +0900, Dirk van Deun wrote: > A very short and simple question: is there a function to "unextend" an > object ? Might this suffice? class Object def unextend(mod) (mod.instance_methods + mod.private_instance_methods + mod.protected_instance_methods).uniq.each do |m| instance_eval "undef #{m}" end end end class A def each; yield 1; end end a = A.new a.extend(Enumerable) puts a.map { |e| e + 1 } # => 2 a.unextend(Enumerable) puts a.map { |e| e + 1 } # => -:17: undefined method `map' for # (NoMethodError) -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk