Project

General

Profile

Feature #12352

New hash syntax broken for numeric keys

Added by adrianomitre (Adriano Mitre) over 3 years ago. Updated over 3 years ago.

Status:
Rejected
Priority:
Normal
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}

History

Updated by shyouhei (Shyouhei Urabe) over 3 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 CommonRuby

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

Updated by matz (Yukihiro Matsumoto) over 3 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) over 3 years ago

  • Status changed from Assigned to Rejected

Also available in: Atom PDF