Project

General

Profile

Actions

Feature #9047

closed

Alternate hash key syntax for symbols

Added by jamonholmgren (Jamon Holmgren) about 11 years ago. Updated about 10 years ago.

Status:
Closed
Target version:
[ruby-core:57993]

Description

=begin

In Ruby, if you can create a symbol with ((|:"symbolname"|)), it seems consistent to allow moving the colon to the right side in a hash and dropping the hash rocket (=>).

{
:str => "v", # symbol
str: "v", # symbol
:"str" => "v", # symbol
"str": "v", # should also be a symbol
}

It would look like this:

h = {
"mykey": "value",
"otherkey": "othervalue",
regular_symbol: "value"
}

String and other non-symbol keys would retain the hash rocket syntax to avoid ambiguity.

{
"string" => "v",
MyObj.new => "v",
@my_var => "v"
}

Thoughts?

=end


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #4276: Allow use of quotes in symbol syntactic sugar for hashesClosedmatz (Yukihiro Matsumoto)01/13/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0