Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.

http://bugs.ruby-lang.org/issues/5540

$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.