Skip to content

Commit 79430da

Browse files
committed
Remove colon from Hash key symbols
1 parent 48d487d commit 79430da

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/debug/variable_inspector.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def named_members_of(obj)
1818
return [] if NaiveString === obj
1919

2020
members = case obj
21-
when Hash then obj.map { |k, v| Variable.new(name: value_inspect(k), value: v) }
21+
when Hash then obj.map { |k, v| Variable.new(name: inspect_hash_key(k), value: v) }
2222
when Struct then obj.members.map { |name| Variable.new(name: name, value: obj[name]) }
2323
when String
2424
members = [
@@ -54,6 +54,15 @@ def value_inspect(obj, short: true)
5454
self.class.value_inspect(obj, short: short)
5555
end
5656

57+
def inspect_hash_key(key)
58+
# Special-case for symbols so debugger UIs render `a: 1` instead of two colons like `:a: 1`
59+
return key.to_s if key.is_a?(Symbol)
60+
61+
value_inspect(key)
62+
end
63+
64+
MAX_LENGTH = 180
65+
5766
def self.value_inspect(obj, short: true)
5867
# TODO: max length should be configurable?
5968
str = LimitedPP.safe_inspect obj, short: short, max_length: MAX_LENGTH
@@ -65,8 +74,6 @@ def self.value_inspect(obj, short: true)
6574
end
6675
end
6776

68-
MAX_LENGTH = 180
69-
7077
# TODO: Replace with Reflection helpers once they are merged
7178
# https://github.com/ruby/debug/pull/1002
7279
M_INSTANCE_VARIABLES = method(:instance_variables).unbind

test/debug/variable_inspector_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_named_members_of_hash
4848

4949
expected = [
5050
Variable.internal(name: '#class', value: Hash),
51-
Variable.new(name: ':sym', value: "has Symbol key"),
51+
Variable.new(name: 'sym', value: "has Symbol key"),
5252
Variable.new(name: '"str"', value: "has String key"),
5353
Variable.new(name: '1', value: "has Integer key"),
5454
]

0 commit comments

Comments
 (0)