@@ -145,31 +145,22 @@ module PPMethods
145145 # Yields to a block
146146 # and preserves the previous set of objects being printed.
147147 def guard_inspect_key
148- if Thread . current [ :__recursive_key__ ] == nil
149- Thread . current [ :__recursive_key__ ] = { } . compare_by_identity
150- end
151-
152- if Thread . current [ :__recursive_key__ ] [ :inspect ] == nil
153- Thread . current [ :__recursive_key__ ] [ :inspect ] = { } . compare_by_identity
154- end
155-
156- save = Thread . current [ :__recursive_key__ ] [ :inspect ]
157-
148+ recursive_state = Thread . current [ :__recursive_key__ ] ||= { } . compare_by_identity
149+ save = recursive_state [ :inspect ] ||= { } . compare_by_identity
158150 begin
159- Thread . current [ :__recursive_key__ ] [ :inspect ] = { } . compare_by_identity
151+ recursive_state [ :inspect ] = { } . compare_by_identity
160152 yield
161153 ensure
162- Thread . current [ :__recursive_key__ ] [ :inspect ] = save
154+ recursive_state [ :inspect ] = save
163155 end
164156 end
165157
166158 # Check whether the object_id +id+ is in the current buffer of objects
167159 # to be pretty printed. Used to break cycles in chains of objects to be
168160 # pretty printed.
169161 def check_inspect_key ( id )
170- Thread . current [ :__recursive_key__ ] &&
171- Thread . current [ :__recursive_key__ ] [ :inspect ] &&
172- Thread . current [ :__recursive_key__ ] [ :inspect ] . include? ( id )
162+ recursive_state = Thread . current [ :__recursive_key__ ] or return false
163+ recursive_state [ :inspect ] &.include? ( id )
173164 end
174165
175166 # Adds the object_id +id+ to the set of objects being pretty printed, so
@@ -186,7 +177,7 @@ def pop_inspect_key(id)
186177 private def guard_inspect ( object )
187178 recursive_state = Thread . current [ :__recursive_key__ ]
188179
189- if recursive_state && recursive_state . key? ( :inspect )
180+ if recursive_state & .key? ( :inspect )
190181 begin
191182 push_inspect_key ( object )
192183 yield
0 commit comments