Hi --

I've become intrigued by the idea of unextending objects -- that is,
removing capabilities from them module-wise.

A couple of things that have been mentioned here recently that relate
at least very indirectly to this are: the idea of a "clean" root class
for objects; and the discussion about inheritance (especially from
core classes) leaving an object with "extra" methods.  In general, all
of these thoughts seem to pertain to the idea of a the granularity of
the modular, "plug-in" capabilities of Ruby objects.

Anyway, I don't have any big idea in mind.  Just playing around with
the idea of being able to add and remove modules at run-time.  My
current little testbed for this looks like this:

  # Object#stretch(aModule) -- extend only for duration of block
  class Object
    def stretch(mod)
      c = class << self; self; end
      before = methods
      extend(mod)
      yield
      (methods - before).each { |m| c.class_eval {undef_method(m)} }
    end
  end

  # Demo
  module Stuff
    def talk; puts "hi"; end
  end

  a = [1,2,3]
  a.stretch(Stuff) { a.talk }   # hi
  p a.respond_to?(:talk)        # false

This has a kind of aesthetic or maybe narrative appeal to me: the
capabilities required of an object for a given purpose exist only at a
kind of flashpoint, the exact place and time where they're needed, and
then they disappear again.

I'm interested in whether people have done things like this before,
whether it looks like the kind of thing one would ever actually use,
etc.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav