Chris Zetter

Ruby Parsing Bug

A parsing bug in ruby 1.9.2 allowed you to pass blocks to methods preceded by a comma. The bug only affected blocks with do/end and was fixed in 1.9.3.

$ rvm use ruby 1.8.7

[1].inject :+, do |x| 1 end
# => SyntaxError: compile error
# => (irb):1: syntax error, unexpected kDO_BLOCK

$ rvm use ruby 1.9.2 # tested on ruby-1.9.2-p290

[1].inject :+, do |x| 1 end
# => 1

[1].inject :+, {|x| 1}
# => SyntaxError: (irb):2: syntax error, unexpected '|', expecting '}'

$ rvm use ruby 1.9.3

[1].inject :+, do |x| 1 end
# => SyntaxError: (irb):1: syntax error, unexpected keyword_do_block

Read more by me, follow me on twitter or subscribe.