Project

General

Profile

Actions

Feature #12352

closed

New hash syntax broken for numeric keys

Added by adrianomitre (Adriano Mitre) almost 8 years ago. Updated about 2 years ago.

Status:
Rejected
Target version:
-
[ruby-core:75375]

Description

[Matz himself showed in RubyConf 2015 the following example]:

h = { 1: 2, 2: 4, 3: 6 }

Which gives

SyntaxError: unexpected ':', expecting =>
h = { 1: 2, 2: 4, 3: 6 }
        ^

but which should give identical results to

>> h = { 1 => 2, 2 => 4, 3 => 6 }
=> {1=>2, 2=>4, 3=>6}

Updated by shyouhei (Shyouhei Urabe) almost 8 years ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)
  • Tracker changed from Bug to Feature
  • Project changed from Ruby master to 14

Matz, do you want numeric keys for new hash syntax?

Updated by matz (Yukihiro Matsumoto) almost 8 years ago

Although I admit my mistake, I reject this for consistency.
If I allow this syntax, it had to generate

h = {1: 2}
p h # => {:"1", 2}

and no one want this.

Matz.

Updated by matz (Yukihiro Matsumoto) almost 8 years ago

  • Status changed from Assigned to Rejected
Actions #4

Updated by hsbt (Hiroshi SHIBATA) about 2 years ago

  • Project changed from 14 to Ruby master
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0