From: Matt Maycock Date: 2004-12-25T04:28:51+09:00 Subject: Re: SimpleDelegate (was Re: Inconsistency with IO.readlines) > Thank you for walking through this with me. No prob :-) > > handle = nil > > input_reader(some_arg) {|handle| ...} > > handle.puts "Meow Mix Please Deliver" > > Hmm, but the code I saw was: > > > block = Proc.new {|source| > > getter = SimpleDelegator.new(source) > > yield getter > > getter.__setobj__(nil) > > } > > You're worried that "getter" may have existed outside input_reader(), > in the calling code, and you want it to be immediately obvious if you > trample that value? So I think there's a chance what you're saying is what I meant - but maybe not (due to natural language ambiguity -- for me arising from the `but' in your `Hmm, but the code I saw was:') So the variable block is there make the delegator `getter' - send it to the block that was invoked with input_reader, and then have `getter' delegate to nil. The reason for this is that if you passed nil or '-' to input_reader, then (had the __set_obj__ not been invoked after yield), then the `handle' variable above would have been valid to use as an IO object. However, this would not be so if a filename was given (as that IO object would have been closed by the File#open method after the execution of block#[]). This way, both forms of invocation ($stdin and fileIO) behave the same way wrt the block variable getter that is passed to yield, before and after return from #input_reader. So I think that's exactly what you mean - but I just reworded/reiterated it to make sure. -- There's no word in the English language for what you do to a dead thing to make it stop chasing you.