From: William James Date: 2008-12-07T05:48:50+09:00 Subject: Re: Ruby 1.8.7 Lambas: syntax and scoping issue (are these bugs? Charlton Wang wrote: > I'm seeing two odd behaviours with using lambdas: > > 1. It seems as though having a lambda as a function argument with a > block causes a syntax error. It can be mitigated by adding a semicolon > or by using parentheses > > def foo(rest) > puts rest.inspect > yield > end > > > # fails syntax error > foo :parm1=>1, :parm2=>lambda { puts "lambda" } do > puts "In bar block" > end The syntax is wrong whether or not you are passing a Proc object as an argument. def foo(rest) puts rest.inspect yield end ==>nil foo 'hello' { puts 'in block' } SyntaxError: compile error (irb):5: syntax error foo 'hello' { puts 'in block' } ^ (irb):5: syntax error from (irb):5 from :0 foo( 'hello' ){ puts 'in block' } "hello" in block ==>nil foo( proc{p "I'm neither sheep nor lambda."} ){ puts 'in block' } # in block ==>nil