Project

General

Profile

Actions

Feature #6375

closed

Python notation for literal Hash

Added by alexeymuranov (Alexey Muranov) almost 12 years ago. Updated almost 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:44743]

Description

Is there a reason not to use Python notation for literal Hash as an alternative to Ruby notation? I would like to be able to write either { 'a' => 'b', 'c' => 'd' } or { 'a' : 'b', 'c' : 'd' }, and either { :a => 'b' } or { :a: 'b' } .

I find { a: 'b' } to be a confusing alternative to { :a => 'b' }, and do not use it because of this (because it cannot be used if the key is not a symbol).

Updated by alexeymuranov (Alexey Muranov) almost 12 years ago

I guess i am not using { a: 'b' } because what goes in my head is: "Poor new Ruby user who might need to read this..."

Updated by matz (Yukihiro Matsumoto) almost 12 years ago

  • Status changed from Open to Rejected

The suggested changes will break almost every program after 1.9.
Ruby is not Python. Please get used to Ruby-way when you are using Ruby.

Matz.

Updated by alexeymuranov (Alexey Muranov) almost 12 years ago

Ok. However, i was not proposing to remove the 1.9 syntax: { a: 'b' } could be a shorthand notation for { :a: 'b' }, like "#@x #@y" is a shorthand notation for "#{@x} #{@y}".

Alexey.

Updated by matz (Yukihiro Matsumoto) almost 12 years ago

And repeating myself, when {a: 'b'} is a shorthand for {:a => 'b'},
naturally {'a': 'b'} should be {:'a' => 'b'} that is another form of
{:a => 'b'} in Ruby.

Matz.

Updated by alexeymuranov (Alexey Muranov) almost 12 years ago

Matz, currently { 'a': 'b' } does not work in Ruby, do you propose that it be a synonym for { :a => 'b' } in a future version? If not, i do not see your point. The { a: 'b' } syntax is already exceptional, i do not think it will become even more exceptional if { :a : 'b' } for { :a => 'b' } and { 'a' : 'b' } for { 'a' => 'b' } are added.

(For me it is like omitting curly braces in the special case of interpolating an instance variable in a string: "#@x" works, but "#x" with a local variable x does not.)

Alexey.

Updated by matz (Yukihiro Matsumoto) almost 12 years ago

Hi,

In message "Re: [ruby-core:44761] [ruby-trunk - Feature #6375] Python notation for literal Hash"
on Mon, 30 Apr 2012 08:30:30 +0900, "alexeymuranov (Alexey Muranov)" writes:

|Matz, currently { 'a': 'b' } does not work in Ruby, do you propose that it be a synonym for { :a => 'b' } in a future version? If not, i do not see your point.

For non-identifier symbol, I am positive to add {"a+": "b"} as synonym for {:"a+" => "b"}.

Updated by alexeymuranov (Alexey Muranov) almost 12 years ago

Ok, thanks for the explanation.

Alexey.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0