diff --git a/lib/debug/variable_inspector.rb b/lib/debug/variable_inspector.rb index c304bcc44..084a13b1f 100644 --- a/lib/debug/variable_inspector.rb +++ b/lib/debug/variable_inspector.rb @@ -45,7 +45,7 @@ def indexed_members_of obj, start:, count: def named_members_of obj members = case obj - when Hash then obj.map { |k, v| Member.new(name: value_inspect(k), value: v) } + when Hash then obj.map { |k, v| Member.new(name: inspect_hash_key(k), value: v) } when Struct then obj.members.map { |name| Member.new(name:, value: obj[name]) } when String members = [ @@ -77,6 +77,13 @@ def named_members_of obj private + def inspect_hash_key(key) + # Special-case for symbols so debugger UIs render `a: 1` instead of two colons like `:a: 1` + return key.to_s if key.is_a?(Symbol) + + value_inspect(key) + end + MAX_LENGTH = 180 def value_inspect obj, short: true diff --git a/test/debug/variable_inspector_test.rb b/test/debug/variable_inspector_test.rb index 8419687b9..6025038a8 100644 --- a/test/debug/variable_inspector_test.rb +++ b/test/debug/variable_inspector_test.rb @@ -50,7 +50,7 @@ def test_named_members_of_hash expected = [ Member.internal(name: '#class', value: Hash), - Member.new(name: ':sym', value: "has Symbol key"), + Member.new(name: 'sym', value: "has Symbol key"), Member.new(name: '"str"', value: "has String key"), Member.new(name: '1', value: "has Integer key"), ]