From: Jason Roelofs Date: 2007-11-22T03:10:56+09:00 Subject: Re: Emulating a Groovy feature? ------=_Part_3706_12922853.1195668642366 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Nov 21, 2007 12:24 PM, Jake Cutter wrote: > On Aug 20, 2007 4:07 AM, Robert Klemme wrote: > > x = foo.bar.baz rescue nil > > Interesting thread....glad someone else has hit this need. > > How does the above work, exactly? You're rescuing without a block? > Doesn't it have to be something like: > > begin > x = foo.bar.baz > rescue nil > end > > ? At least the documentation would suggest so... > > Thanks, > Jake > > You don't need begin unless you want to catch just a section of code. Single lines works wonders for concise error handling, such as this_method_can_throw rescue "default value" Or for a full method (Rails) def action does_stuff_that_can_throw rescue default_error_handling end Ruby's awesome. Jason ------=_Part_3706_12922853.1195668642366--