
Issue #20433 has been updated by zverok (Victor Shepelev).
ambiguous keys should be wrapped by (double) quotation marks
BTW, if the change is so radical, can we also (start to) adopt Python’s flexible quotation marks? (For now, only for Hash keys, but once, maybe, for strings): ```python print("test 'quotes'".__repr__()) #=> "test 'quotes'" print('test "quotes"'.__repr__()) #=> 'test "quotes"' ``` I.e. make it so for Hash keys: ```ruby {"'": true, '"': false}.inspect #=> {"'": true, '"': false} ``` ---------------------------------------- Bug #20433: Hash.inspect for some hash returns syntax invalid representation https://bugs.ruby-lang.org/issues/20433#change-109202 * 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/