[BUG] Broken indentation

Gavin Sinclair gsinclair at soyabean.com.au
Sun Apr 10 10:13:39 EDT 2005


On Sunday, April 10, 2005, 11:47:48 PM, Sam wrote:

> Quoting dougkearns at gmail.com, on Sun, Apr 10, 2005 at 11:31:35PM +1000:
>> On Sun, Apr 10, 2005 at 03:04:54PM +0200, Nikolai Weibull wrote:
>> > Gavin Sinclair, April 10:
>> > 
>> > > > foo do
>> > > >   bar
>> > > > rescue
>> > > >   nil
>> > > > end
>> > 
>> > > Is that valid Ruby?  (I wish it was.)  You need an explicit 'begin ...
>> > > end'.  Tilman's point stands.
>> > 
>> > Actually, it's valid;
>> 
>> It is?

> Pretty sure, I found out recently. Handy for doing:

>    foo = method_that_may_raise('an arg') rescue nil

> foo should be set to nil if something derived from StandardError is
> raised, if I recall correctly.

Yes, and that's the syntax Tilman was pointing out.  That is valid
Ruby.  Nikolai misunderstood, suggesting it be rewritten as what you
see above.  The two code fragments are, however, not equivalent.

Tilman's code is valid and does not indent correctly.

Nikolai's code is invalid, but indents correctly :)

Gavin

P.S. I repeat: the following two fragments are _not_ equivalent!

  10.times do
    puts(x) rescue nil
  end

  10.times do
    puts(x)
  rescue
    nil
  end

If the second fragment were legal, they'd be equivalent (I guess) but
only for the special case where there's only one line in the block!







More information about the vim-ruby-devel mailing list