From: James Edward Gray II Date: 2004-12-24T04:18:55+09:00 Subject: SimpleDelegate (was Re: Inconsistency with IO.readlines) Let me apologize in advance, because I've not bee following this thread. I have been working with Gavin Sinclair to document delegate.rb though, and together we've been hard pressed to find a single good use for SimpleDelegate... On Dec 23, 2004, at 1:03 PM, Matt Maycock wrote: > # ========== ext/input_reader.rb ========== > # ext/input_reader.rb > # accept some name argument. if name is nil || '-', > # then use $stdin and send that to the block > # otherwise, use File.open(name, *restargs) > > require 'delegate' > > def input_reader(fname, *fargs) > block = Proc.new {|source| > getter = SimpleDelegator.new(source) > yield getter > getter.__setobj__(nil) > } > > if fname.nil? || fname == '-' then > block[$stdin] > else > File.open(fname, *fargs) {|f| block[f]} > end > end Would you mind explaining to me why you use SimpleDelegate above? I would really appreciate it. James Edward Gray II