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: Document quoted-string-followed-by-colon syntax for Symbol keys in Hash literals #49

Open
das-g opened this issue Jul 18, 2015 · 0 comments

Comments

@das-g
Copy link

das-g commented Jul 18, 2015

In Ruby >= 2.2, the following Hash literals are equivalent:

  1. { :my_key => 5 }

    (Symbol literal used as key in the generic hash literal notation that'd work for non-Symbol keys, too.)
  2. { my_key: 5 }

    (Symbol-key-specific "JavaScript-like" new notation introduced in Ruby 1.9)
  3. { :"my_key" => 5 }

    (Same as (1.), just with a different notation for the Symbol literal. Allows string interpolation inside the symbol name.)
  4. { :'my_key' => 5 }

    (Same as (1.), just with a different notation for the Symbol literal. No string interpolation.)
  5. { "my_key": 5 }

    (Introduced by feature request #4276 in Ruby 2.2. Allows string interpolation inside the symbol name.)
  6. { 'my_key': 5 }

    (Probably also introduced by feature request Move rb_int_coerce ruby/ruby#4276. No string interpolation.)

While (1.) & (2.) are documented on http://ruby-doc.org/core-2.2.2/Hash.html and (3.) & (4.) follow from (1.) when plugging in the alternate Symbol literal notations, (5.) & (6.) seem to be undocumented yet.

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

1 participant