Curiosity about syntax for multi-line statements

Hi,

I posted at http://www.pastie.org/536025 four different continuation
schemes for a lengthy statement. The first three work fine, but the
fourth fails. (The question arose as I was importing columnar
positions for selected columnar headings in a CSV file.)

Did I make a mistake or did the Ruby parser?

I’m running:
ruby 1.8.6
WinXP-Pro/SP2

Thanks in advance,
Richard

On Jul 6, 2009, at 11:54 AM, RichardOnRails wrote:

Hi,

I posted at http://www.pastie.org/536025 four different continuation
schemes for a lengthy statement. The first three work fine, but the
fourth fails. (The question arose as I was importing columnar
positions for selected columnar headings in a CSV file.)

Did I make a mistake or did the Ruby parser?

Fails how? As is, with my install (ruby 1.8.6 (2008-08-11 patchlevel
287) [universal-darwin9.0]) I get this for the 4th:

%s = %d
%s = %d
Date = 0

But don’t get an error. I think it’s a precedence problem. My guess
is % binds tighter than +, but I haven’t verified that. Adding some
()'s around the strings and it works like you’d expect.

puts (“4.\n %s = %d\n” +
" %s = %d\n" +
" %s = %d\n") % [
:Date.to_s, date,
:Description.to_s, description,
:Amount.to_s, amount]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs