Skip to content

Commit

Permalink
Remove colon from Hash key symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
amomchilov committed Jan 4, 2024
1 parent 2e850bc commit 46c0421
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/debug/variable_inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def named_members_of(obj)
return [] if NaiveString === obj

members = case obj
when Hash then obj.map { |k, v| Variable.new(name: value_inspect(k), value: v) }
when Hash then obj.map { |k, v| Variable.new(name: inspect_hash_key(k), value: v) }
when Struct then obj.members.map { |name| Variable.new(name: name, value: obj[name]) }
when String
members = [
Expand Down Expand Up @@ -50,6 +50,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

def value_inspect(obj, short: true)
self.class.value_inspect(obj, short: short)
end
Expand Down
2 changes: 1 addition & 1 deletion test/debug/variable_inspector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_named_members_of_hash

expected = [
Variable.internal(name: '#class', value: Hash),
Variable.new(name: ':sym', value: "has Symbol key"),
Variable.new(name: 'sym', value: "has Symbol key"),
Variable.new(name: '"str"', value: "has String key"),
Variable.new(name: '1', value: "has Integer key"),
]
Expand Down

0 comments on commit 46c0421

Please sign in to comment.