From: thomass@... (Thomas) Date: 2002-01-20T19:53:57+09:00 Subject: Re: $_ as default parameter for a function Could you, or someone else explain whats going on below? Maybe I should emphasize what it is I want to do! I'm working on a ZipInputStream and a ZipOutputStream, and I would very much like these classes to work like IO, of course. Ideally I would like to have been able to provide a few very basic methods for input and output, and IO would then provide the rest, but IO does not appear to be suited for that, though please tell me if I'm wrong. So rather than subclassing IO I have implemented two modules InputStream and OutputStream that you can mixin. In order to work like the i/o methods in IO, I often need to fall back to the value of $_ in the calling scope as a default value. Any ideas? Thomas Mathieu Bouchard wrote in message > Yes, $_ is a local, and yes, built-in methods have access to the $_ of the > caller. Here's an excerpt from MetaRuby 0.7 in module HollowString: > > # it's your own fault for using ~ > def ~ > # setting up quantum superposition > r,w = IO.pipe > if not fork then > set_trace_func(proc{|*a| > w.puts(eval("$_", a[4]).inspect) > exit! > }) > else > Process.wait > eval(r.readline) =~ self.to_str > end > end