Skip to content

Instantly share code, notes, and snippets.

@zetter
Created March 9, 2012 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zetter/2009199 to your computer and use it in GitHub Desktop.
Save zetter/2009199 to your computer and use it in GitHub Desktop.
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