Skip to content

Commit 5605708

Browse files
committed
refactor
1 parent 5618df3 commit 5605708

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/json_mend/parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def parse
6363
# Ignore strings that look like closing braces garbage (e.g. "}", " ] ")
6464
next if new_json.is_a?(String) && new_json.strip.match?(/^[}\]]+$/)
6565

66-
json.pop if same_object_type?(json.last, new_json)
66+
json.pop if both_hash?(json.last, new_json)
6767
json << new_json
6868
end
6969
end
@@ -1121,7 +1121,7 @@ def skip_whitespaces_at(start_idx: 0)
11211121
res
11221122
end
11231123

1124-
def same_object_type?(obj1, obj2)
1124+
def both_hash?(obj1, obj2)
11251125
obj1.is_a?(Hash) && obj2.is_a?(Hash)
11261126
end
11271127

spec/json_mend_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ def with_timeout(seconds = 1, &)
700700
context 'when provided tricky edge cases and malformed structures' do
701701
[
702702
# Duplicate keys: The parser splits this into two objects [{"k":"v1"}, {"k":"v2"}]
703-
# The main loop then sees two Hashes and keeps the last one (same_object_type? logic)
703+
# The main loop then sees two Hashes and keeps the last one (both_hash? logic)
704704
{
705705
input: '{"key": "v1", "key": "v2"}',
706706
expected_output: JSON.dump({ 'key' => 'v2' })

0 commit comments

Comments
 (0)