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.