Actions
Bug #11604
closedRuby's interpreting hash symbol keys as parts of Ruby syntax
Description
Cannot initialize hashes with some Ruby reserved keywords like: while, until, if, unless, do. Can with other like class, end, elsif, super. Don't really get why
{ while: 1 } # Will fail
# error.rb:3: syntax error, unexpected ':'
# print { while: 1 }
However when assigned, works perfectly
hash = { while: 1 }
But when used as a method argument - fails
run(for: 1)
run { for: 1 }
Works with old syntax
{ :if => 1 }
And with new but with quotation marks
{ 'if': 1 }
Example file included. Please just execute like this:
ruby error.rb
Files
Actions
Like0
Like0Like0Like0