Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
5eef75b6
Unverified
Commit
5eef75b6
authored
Jul 17, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jul 17, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4034 from i110/i110/inspect-recursion
Let inspect recursion do the right thing
parents
9af3b7c6
d605b72c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
25 deletions
+23
-25
mrbgems/mruby-struct/mrblib/struct.rb
mrbgems/mruby-struct/mrblib/struct.rb
+5
-7
mrbgems/mruby-struct/test/struct.rb
mrbgems/mruby-struct/test/struct.rb
+4
-3
mrblib/array.rb
mrblib/array.rb
+5
-7
mrblib/hash.rb
mrblib/hash.rb
+4
-6
mrblib/kernel.rb
mrblib/kernel.rb
+1
-1
test/t/array.rb
test/t/array.rb
+2
-1
test/t/hash.rb
test/t/hash.rb
+2
-0
No files found.
mrbgems/mruby-struct/mrblib/struct.rb
View file @
5eef75b6
...
...
@@ -46,7 +46,9 @@ if Object.const_defined?(:Struct)
ary
end
def
_inspect
def
_inspect
(
recur_list
)
return
"#<struct
#{
self
.
class
}
:...>"
if
recur_list
[
self
.
object_id
]
recur_list
[
self
.
object_id
]
=
true
name
=
self
.
class
.
to_s
if
name
[
0
]
==
"#"
str
=
"#<struct "
...
...
@@ -55,7 +57,7 @@ if Object.const_defined?(:Struct)
end
buf
=
[]
self
.
each_pair
do
|
k
,
v
|
buf
.
push
[
k
.
to_s
+
"="
+
v
.
_inspect
]
buf
.
push
[
k
.
to_s
+
"="
+
v
.
_inspect
(
recur_list
)
]
end
str
+
buf
.
join
(
", "
)
+
">"
end
...
...
@@ -70,11 +72,7 @@ if Object.const_defined?(:Struct)
# 15.2.18.4.10(x)
#
def
inspect
begin
self
.
_inspect
rescue
SystemStackError
"#<struct
#{
self
.
class
.
to_s
}
:...>"
end
self
.
_inspect
({})
end
##
...
...
mrbgems/mruby-struct/test/struct.rb
View file @
5eef75b6
...
...
@@ -116,9 +116,10 @@ assert('struct dup') do
end
assert
(
'struct inspect'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
)
cc
=
c
.
new
(
1
,
2
,
3
,
4
,
5
)
assert_equal
"#<struct m1=1, m2=2, m3=3, m4=4, m5=5>"
,
cc
.
inspect
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
,
:recur
)
cc
=
c
.
new
(
1
,
2
,
3
,
4
,
5
,
nil
)
cc
.
recur
=
cc
assert_equal
"#<struct m1=1, m2=2, m3=3, m4=4, m5=5, recur=#<struct
#{
cc
.
class
}
:...>>"
,
cc
.
inspect
end
assert
(
'Struct#length, Struct#size'
)
do
...
...
mrblib/array.rb
View file @
5eef75b6
...
...
@@ -83,13 +83,15 @@ class Array
self
end
def
_inspect
def
_inspect
(
recur_list
)
size
=
self
.
size
return
"[]"
if
size
==
0
return
"[...]"
if
recur_list
[
self
.
object_id
]
recur_list
[
self
.
object_id
]
=
true
ary
=
[]
i
=
0
while
i
<
size
ary
<<
self
[
i
].
inspect
ary
<<
self
[
i
].
_inspect
(
recur_list
)
i+=1
end
"["+ary.join(", ")+"]"
...
...
@@ -99,11 +101,7 @@ class Array
#
# 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
...
...
mrblib/hash.rb
View file @
5eef75b6
...
...
@@ -186,8 +186,10 @@ class Hash
end
# internal method for Hash inspection
def
_inspect
def
_inspect
(
recur_list
)
return
"{}"
if
self
.
size
==
0
return
"{...}"
if
recur_list
[
self
.
object_id
]
recur_list
[
self
.
object_id
]
=
true
ary
=
[]
keys
=
self
.
keys
size
=
keys
.
size
...
...
@@ -204,11 +206,7 @@ class Hash
#
# ISO 15.2.13.4.30 (x)
def
inspect
begin
self
.
_inspect
rescue
SystemStackError
"{...}"
end
self
.
_inspect
({})
end
# ISO 15.2.13.4.31 (x)
alias
to_s
inspect
...
...
mrblib/kernel.rb
View file @
5eef75b6
...
...
@@ -40,7 +40,7 @@ module Kernel
end
# internal method for inspect
def
_inspect
def
_inspect
(
_recur_list
)
self
.
inspect
end
...
...
test/t/array.rb
View file @
5eef75b6
...
...
@@ -346,11 +346,12 @@ end
assert
(
'Array#to_s'
,
'15.2.12.5.31 / 15.2.12.5.32'
)
do
a
=
[
2
,
3
,
4
,
5
]
a
[
4
]
=
a
r1
=
a
.
to_s
r2
=
a
.
inspect
assert_equal
(
r2
,
r1
)
assert_equal
(
"[2, 3, 4, 5]"
,
r1
)
assert_equal
(
"[2, 3, 4, 5
, [...]
]"
,
r1
)
end
assert
(
'Array#=='
,
'15.2.12.5.33'
)
do
...
...
test/t/hash.rb
View file @
5eef75b6
...
...
@@ -352,11 +352,13 @@ end
assert
(
'Hash#inspect'
)
do
h
=
{
"c"
=>
300
,
"a"
=>
100
,
"d"
=>
400
,
"c"
=>
300
}
h
[
"recur"
]
=
h
ret
=
h
.
to_s
assert_include
ret
,
'"c"=>300'
assert_include
ret
,
'"a"=>100'
assert_include
ret
,
'"d"=>400'
assert_include
ret
,
'"recur"=>{...}'
end
assert
(
'Hash#rehash'
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment