Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Syntax error with "do"-block in Local scope

#8

The following code works:

[1,2,3].each do |n|
  puts(n.to_s())

But this fails:

[1,2,3].each do |n|
  puts(n.to_s())

puts("Now it dies")

The following stacktrace is returned:

exception: {exception,
               {throw,
                   {tuple,
                       {error,
                           {tuple,
                               {4,
                                {list,{[],"syntax error before: puts"}}}}}}}}
stacktrace: [{'Eval',string,1},
             {'Loader',eval_input,1},
             {init,start_it,1},
             {init,start_em,1}]

Defining the do-block code in ire works, as does defining the same functionality with a curly braces block:

[1,2,3].each { |n| puts(n.to_s()) }
puts("Now it lives")

The code samples can also be found at: http://gist.github.com/30494

It looks to me as if the do-block is somehow not properly closed when parsed from a file in the Local scope. This explains why it does work when it is the last thing in the file or in ire. The fact that it works when the code is defined as a method in a class is puzzling.

Reported by Wes Oldenbeuving · November 30th, 2008 @ 12:23 PM

State: new
Milestone: none
Assigned to: nobody

Activity

No comments yet.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.