[ruby-core:117570] [Ruby master Bug#20433] Hash.inspect for some hash returns syntax invalid representation
From:
"byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Date:
2024-04-17 17:13:02 UTC
List:
ruby-core #117570
Issue #20433 has been updated by byroot (Jean Boussier).
An easy fix would be for `Hash#inspect` to include spaces around `=>`. It would also read much nicer in my opinion.
----------------------------------------
Bug #20433: Hash.inspect for some hash returns syntax invalid representation
https://bugs.ruby-lang.org/issues/20433#change-107967
* Author: tompng (tomoya ishida)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
For these hashes, Hash.inspect returns a syntax invalid representation:
~~~ruby
{ :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
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/