On Mon, 8 Jan 2001, Ben Tilly wrote:

> I have mentioned before, perhaps I should mention again.
> 
> The right container modules would (when combined with
> mix-ins) provide a complete equivalent to Perl's tie.
> As things stand someone who wanted to write a version
> of Hash or Array which was tied to disk through a dbm
> library like Berkeley DB would need to reimplement a
> lot of methods.

True, but when you write STORE() and FETCH() and all that in Perl,
you're also reimplementing a lot of methods.  One could argue the
other way -- namely, that in Ruby, the basic mechanism for redefining
methods is so powerful that *all* you have to do to get tie
functionality is reimplement some methods.  They happen to be called
things like #[]=, rather than STORE(), but they're already there.

To put it another way: even a "naive" Ruby approach to creating a
tied hash:

   class SomeTiedHash < Hash

     alias ....

     def initialize(*n)
       # do some stuff, open a file, whatever
       super(*n)
     end

     def []=(k,v)
       oldset(k,v)
       @fh.puts "#{k}: #{v}"..... 
     end
        
   end

does actually create a tied hash.  I'm not saying there are no
possible reasons to do some modularization and so forth -- but I don't
see any big obstacles or logjams to doing tied things already.


David

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