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

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:

4.
  %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]

Hi Philip,

Excellent reply. Thanks!

Fails how? [snip]
4.
  %s = %d
  %s = %d
  Date = 0

That's what I got, too, but I expected the same result as the previous
three ... and that's "failure" in my book :slight_smile:

I think it's a precedence problem.

That's the idea I really wanted and failed to deduce myself. Yep,
parens worked for me, too. Again, thanks!

Best wishes,
Richard