From: evanm@... Date: 2004-06-23T02:49:26+09:00 Subject: Re: Cleaning up IO#popen On Tue, Jun 22, 2004 at 08:32:06AM +0900, nobu.nokada@softhome.net wrote: > You can give arguments as an Array. e.g.: > > IO.popen(%w[echo |arguments| contain shell's "chars"], "r") Great, that's also a workable way. > > it work? What is its args? Does it drop the '-' and mode arguments? > > I'm not sure they are really evil. Parsing a string for magic arguments moves logic from the code into the data. It's poor design. Why not have a separate function with all the benefits that brings? AFAIK there aren't any benefits in parsing magic values from a string, but if you allow "-" then the programmer has to special case every string he passes to verify that it's not "-" or risk running the wrong function. There are many more elegant ways of doing this, but the best is to not do it at all. > At Mon, 21 Jun 2004 06:06:02 +0900, > evanm@frap.net wrote in [ruby-talk:104194]: > > * takes a "mode string" arg for what really should be a separate function > > * takes a "-" as a magic value for what really should be a separate function > > Do you suggest to provide all possible combinations? I suggest the code I submitted for IO.fork_open. There are only two options, reading and writing, and this can be done in one with my implementation of IO.fork_open which provides a bidirectional pipe. IO.pread and IO.pwrite would be preferable to IO.popen with a mode argument, IMHO. Evan