Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash: JavaScript-like colon notation allowed for Symbol keys, even when other key in the same Hash aren't Symbols #50

Closed
das-g opened this issue Jul 18, 2015 · 2 comments

Comments

@das-g
Copy link

das-g commented Jul 18, 2015

On http://ruby-doc.org/core-2.2.2/Hash.html#method-i-store, the notation { my_key: 5 } (available since Ruby 1.9) is introduced with

Hashes allow an alternate syntax form when your keys are always symbols.

(Emphasis mine.)

This suggests that this syntax will only be allowed for literals of Hashes where all keys are are Symbols. However, experiments show it works fine for Hashes of mixed key types:

{"a string" => 1, a_symbol: 2, Math::PI => 3 }

(Of course, the colon syntax can only be used for those keys that are Symbols.)

@das-g
Copy link
Author

das-g commented Jul 18, 2015

I suggest to change that to

Hashes allow an alternate syntax form for keys that are symbols:

das-g added a commit to das-g/ruby that referenced this issue Jul 18, 2015
…ype-keyed Hashes

The JavaScript-like colon notation is allowed for Symbol keys, even when other key in the same Hash aren't Symbols

documenting-ruby#50
@zzak
Copy link

zzak commented Aug 7, 2015

@das-g Thank you for your patch!

This was committed in r51506.

@zzak zzak closed this as completed Aug 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants