From: dblack@... Date: 2002-12-15T23:57:29+09:00 Subject: Re: un-extending objects Hi -- On Sun, 15 Dec 2002, ts wrote: > a = A.new > a.a > a.stretch(M) { a.a } > a.a > pigeon% > > pigeon% b.rb > a > b > b > pigeon% Do we consider that a bug or a feature? :-) OK, the slightly less compact second iteration: class Object def stretch(mod) c = class << self; self; end before = methods cache = {} mod.instance_methods.select {|m| respond_to?(m)}.each do |m| alt = "__#{id}__#{m}" c.send(:alias_method,alt,m) cache[alt] = m end extend(mod) yield cache.each {|alt,m| c.send(:alias_method,m,alt)} (methods - before).each { |m| c.class_eval {undef_method(m)} } end end I'd rather do this by binding and unbinding methods... but that technique doesn't seem to fit exactly. And there must be thread-related problems with this (aren't there always? :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav