I know it's not quite the same thing but if all you're checking for is
file existence, you can always do:

File.exists?("/path/to/file")  # => true/false


On Wed, Aug 4, 2010 at 5:18 PM, Darren Boyd <[email protected]> wrote:

> f = File.open(blah) rescue abort('cannot open file')
>
>
> On Wed, Aug 4, 2010 at 2:06 PM, Glenn Little <[email protected]> wrote:
> > Just curious if there is an elegant ruby idiom for opening a file and
> > getting out with minimal fuss if the file can't be opened.  Something
> > like perl's
> >
> >  open(blah blah) || die "cannot open file"
> >
> > The obvious seems to be ruby's
> >
> >  begin
> >    f = File.open(blah)
> >  rescue
> >    abort "cannot open file"
> >  end
> >
> > While that does give me a heck of a lot more fine-grained control over
> > responding to different error types and so on, it seems a little bulky
> > and verbose if all I really want is a quick message and a non-zero
> > exit status.
> >
> > Am I missing an option or idiom?
> >
> > Thanks!
> >
> > -glenn
> >
> > --
> > SD Ruby mailing list
> > [email protected]
> > http://groups.google.com/group/sdruby
>
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
>

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to