Project

General

Profile

Actions

Feature #9445

closed

Support emitting 1.9 Symbol keyword Hash syntax when pretty printing Hashes

Feature #9445: Support emitting 1.9 Symbol keyword Hash syntax when pretty printing Hashes

Added by postmodern (Hal Brodigan) almost 13 years ago. Updated about 10 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:60043]

Description

Ruby 1.9 first introduced support for keyword Hash syntax for simple Symbol keys. However, Hash#inspect and pp do not emit the same syntax when printing Symbol keys. This patch adds support for "foo: " syntax to the pp_hash method, iff the key is a Symbol and does not contain any spaces or special characters. While the patch is probably not perfect, I hope to start a discussion.


Files

pp.patch (529 Bytes) pp.patch Patches the pp_hash method to emit "foo: " syntax for Symbol Hash keys postmodern (Hal Brodigan), 01/24/2014 02:11 AM

Related issues 1 (0 open — 1 closed)

Related to Ruby - Bug #20433: Hash.inspect for some hash returns syntax invalid representationClosedActions

Updated by nobu (Nobuyoshi Nakada) almost 13 years ago Actions #1 [ruby-core:60051]

Mixing foo: and bar => doesn't seem pretty to me.

Updated by postmodern (Hal Brodigan) almost 13 years ago Actions #2 [ruby-core:60053]

While it may not be pretty, it is still valid Ruby syntax. If others disagree with mixing the two syntaxes, I can adjust the patch.

Updated by phluid61 (Matthew Kerwin) almost 13 years ago Actions #3 [ruby-core:60054]

I think it's better to not add unnecessary complexity. After all, we don't represent strings with single quotes, even when they don't contain escaped characters, and even when they do contain double-quote characters.

Updated by Earlopain (Earlopain _) about 10 hours ago Actions #4

  • Related to Bug #20433: Hash.inspect for some hash returns syntax invalid representation added

Updated by Earlopain (Earlopain _) about 10 hours ago Actions #5

  • Status changed from Open to Closed
Actions

Also available in: PDF Atom