Nice to hear Perl's "die" described as elegant. I think it was maybe Kent Beck who said he thought it was like committing suicide because you missed the bus.

On 8/4/2010 2:06 PM, Glenn Little 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

Reply via email to