How about this?

File.open(blah) do |f|
  ...stuff...
end rescue abort("cannot open file")


- John

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

Reply via email to