From 2af92d0ebcbeca6d3d85a27c8193273080a63090 Mon Sep 17 00:00:00 2001 From: Ichito Nagata Date: Mon, 4 Jun 2018 10:52:51 +0900 Subject: Let inspect recursion do the right thing --- mrblib/array.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'mrblib/array.rb') diff --git a/mrblib/array.rb b/mrblib/array.rb index 334f4e984..bc9a2a492 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -83,20 +83,18 @@ class Array self end - def _inspect + def _inspect(recur_list) return "[]" if self.size == 0 - "["+self.map{|x|x.inspect}.join(", ")+"]" + return "[...]" if recur_list[self.object_id] + recur_list[self.object_id] = true + "["+self.map{|x|x._inspect(recur_list)}.join(", ")+"]" end ## # Return the contents of this array as a string. # # ISO 15.2.12.5.31 (x) def inspect - begin - self._inspect - rescue SystemStackError - "[...]" - end + self._inspect({}) end # ISO 15.2.12.5.32 (x) alias to_s inspect -- cgit v1.2.3