mrubyを超漢字で動作させる
Revisão | 79fb18445dec95c546b43a98b38b541674f89d93 (tree) |
---|---|
Hora | 2014-07-12 23:22:20 |
Autor | Yukihiro "Matz" Matsumoto <matz@ruby...> |
Commiter | Yukihiro "Matz" Matsumoto |
rescue SystemStackError that comes from inspecting self-referencing Hashes and Arrays; fix #2461
@@ -84,13 +84,20 @@ class Array | ||
84 | 84 | self |
85 | 85 | end |
86 | 86 | |
87 | + def _inspect | |
88 | + return "[]" if self.size == 0 | |
89 | + "["+self.map{|x|x.inspect}.join(", ")+"]" | |
90 | + end | |
87 | 91 | ## |
88 | - # Private method for Array creation. | |
92 | + # Return the contents of this array as a string. | |
89 | 93 | # |
90 | 94 | # ISO 15.2.12.5.31 (x) |
91 | 95 | def inspect |
92 | - return "[]" if self.size == 0 | |
93 | - "["+self.map{|x|x.inspect}.join(", ")+"]" | |
96 | + begin | |
97 | + self._inspect | |
98 | + rescue SystemStackError | |
99 | + "[...]" | |
100 | + end | |
94 | 101 | end |
95 | 102 | # ISO 15.2.12.5.32 (x) |
96 | 103 | alias to_s inspect |
@@ -192,16 +192,24 @@ class Hash | ||
192 | 192 | h |
193 | 193 | end |
194 | 194 | |
195 | - ## | |
196 | - # Return the contents of this hash as a string. | |
197 | - # | |
198 | - # ISO 15.2.13.4.30 (x) | |
199 | - def inspect | |
195 | + # internal method for Hash inspection | |
196 | + def _inspect | |
200 | 197 | return "{}" if self.size == 0 |
201 | 198 | "{"+self.map {|k,v| |
202 | - k.inspect + "=>" + v.inspect | |
199 | + k._inspect + "=>" + v._inspect | |
203 | 200 | }.join(", ")+"}" |
204 | 201 | end |
202 | + ## | |
203 | + # Return the contents of this hash as a string. | |
204 | + # | |
205 | + # ISO 15.2.13.4.30 (x) | |
206 | + def inspect | |
207 | + begin | |
208 | + self._inspect | |
209 | + rescue SystemStackError | |
210 | + "{...}" | |
211 | + end | |
212 | + end | |
205 | 213 | # ISO 15.2.13.4.31 (x) |
206 | 214 | alias to_s inspect |
207 | 215 |
@@ -39,6 +39,11 @@ module Kernel | ||
39 | 39 | !(self =~ y) |
40 | 40 | end |
41 | 41 | |
42 | + # internal method for inspect | |
43 | + def _inspect | |
44 | + self.inspect | |
45 | + end | |
46 | + | |
42 | 47 | def to_enum(*a) |
43 | 48 | raise NotImplementedError.new("fiber required for enumerator") |
44 | 49 | end |