Character keys in a hash are sometimes similar to keyword arguments and sometimes not
The character keys in the hash appear to be handled similarly to keyword arguments in the sense that character keys havehes
a = [{a: 1, b: 2}, {a: 3, b: 4}]
the corresponding values โโrefer to the keyword block argument in this expression:
a.each{|a:, b:| ...}
On the other hand, this is an expression where the keyword argument appears in parentheses:
a.each_with_index{|(a:, b:), i| ...}
raises a syntax error:
unexpected tLABEL
a.each_with_index{|(a:, b:), i| }
^
Is this an expected feature or a bug?
+3
source to share
No one has answered this question yet
See similar questions:
or similar: