Skip to content

Commit 3c3e8a1

Browse files
committed
catch more inspect styles.
1 parent 165b8f5 commit 3c3e8a1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/trailblazer/core/utils/inspect.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def self.inspect(object)
77
old_string = object.inspect
88
# old_string = %({{symbol: 1, "string" => 2},"string" => 1})
99

10-
new_string = old_string.gsub(/(\w+): /, ':\1=>')
10+
new_string = old_string.gsub(/([{ ])(\w+): /, '\1:\2=>')
1111
new_string = new_string.gsub(" => ", "=>")
1212

1313
return new_string

test/hash_inspect_test.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ class Memo < Struct.new(:id); end
88
symbol: {symbol: 1, "string" => 2},
99
"string" => 1,
1010
Memo.new(1) => true,
11+
method(:inspect) => 9,
1112
}
1213

14+
#<Method: Trailb
15+
1316
puts Trailblazer::Core::Utils.inspect(hsh)
14-
assert_equal Trailblazer::Core::Utils.inspect(hsh), %({:symbol=>{:symbol=>1, "string"=>2}, "string"=>1, #<struct HashInspectTest::Memo id=1>=>true})
17+
assert_equal Trailblazer::Core::Utils.inspect(hsh), %({:symbol=>{:symbol=>1, "string"=>2}, "string"=>1, #<struct HashInspectTest::Memo id=1>=>true, #<Method: HashInspectTest(Kernel)#inspect()>=>9})
1518
end
1619

1720
it "uses native {#inspect} for other classes" do

0 commit comments

Comments
 (0)