From: Rick DeNatale Date: 2006-08-06T14:10:09+09:00 Subject: Re: Whitespace matters in instance_eval? I'm confused On 8/6/06, Harold Hausman wrote: > irb(main):004:0> foo.instance_eval "3.times\n{ puts 'boom' \n}" > SyntaxError: (eval):3:in `irb_binding': compile error > (eval):2: syntax error > { puts 'boom' > ^ > (eval):3: syntax error > from (irb):4 > > #is there a rule that says that the opening curly brace has to be on > the same line? I think that it pretty much falls out of the way Ruby handles lines in source. As the pickaxe put's it Ruby is 'line-oriented' 1) An expression or statement which looks like complete by the end of the line IS considered complete 2) Blocks are optional in method calls, so 3.times looks like (and is a complete expression, and a complete statement) 3) a bare block is not a valid statement It's got nothing to do with instance_eval irb(main):001:0> 3.times LocalJumpError: no block given from (irb):1:in `times' from (irb):1 irb(main):002:0> { puts "boom" } SyntaxError: compile error (irb):2: parse error, unexpected tSTRING_BEG, expecting kDO or '{' or '(' { puts "boom" } ^ (irb):2: parse error, unexpected '}', expecting $ from (irb):2 irb(main):003:0> -- Rick DeNatale