Project

General

Profile

Actions

Bug #20433

open

Hash.inspect for some hash returns syntax invalid representation

Added by tompng (tomoya ishida) 13 days ago. Updated 12 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:117564]

Description

For these hashes, Hash.inspect returns a syntax invalid representation:

{ :a! => 1 } # {:a!=>1}
{ :a? => 1 } # {:a?=>1}
{ :* => 1 }  # {:*=>1}
{ :== => 1 } # {:===>1}
{ :< => 1 }  # {:<=>1}

eval(hash.inspect) will raise SyntaxError.
Although inspect does not guarantee that the result can be eval-ed, it'd be confusing for these few cases.

Maybe related to https://bugs.ruby-lang.org/issues/20235

Updated by byroot (Jean Boussier) 13 days ago

An easy fix would be for Hash#inspect to include spaces around =>. It would also read much nicer in my opinion.

Updated by nobu (Nobuyoshi Nakada) 12 days ago

Or use {a!: 1} for symbol keys?

Updated by nobu (Nobuyoshi Nakada) 12 days ago

Ditto for pp.rb.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0