From: zuzu Date: 2004-10-02T04:36:16+09:00 Subject: Re: Ruby as a shell (was Re: irb: a great tool in it's own right) http://www.rubyist.net/~rubikitch/computer/irbsh/ -z On Fri, 1 Oct 2004 22:53:07 +0900, Eivind Eklund wrote: > On Fri, 1 Oct 2004 20:17:14 +0900, Kaspar Schiess wrote: > > Just in case anyone is really interested, the def is > > > > ~ def method_missing( method, *args ) > > ~ system method.to_s + " " + args.join(' ') > > ~ end > > > > and you could perhaps call > > > > ~ dir %w{ *.rb } > > > > ++ for the method missing comment ! > > ... etc. > > On the subject (if not the Subject:): Have anybody played with make it > possible to use Ruby for running sort-of shell scripts? Ie, including > pipes etc. As it is, there are some programs that call a lot of shell > commands that I write in sh instead of Ruby, and where I'd really like > to do them in Ruby. > > The starting point I see for something like this would be to override > method_missing like above, but make it return an object where | is > overridden, and that have handling of shell return codes. > > The challenges I see here is > - It's not possible to override the trueness/falseness of an object, > so we'd need to call a special method to find out if a command failed > or passed > - It is hard to implement -e (give an error if a complete shell line > fails - but not if we have an fail || true). Maybe trace_func could > be of help here, though. > > Eivind. > >