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
d9feed67
Commit
d9feed67
authored
Apr 01, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move Array#inspect implementation to mrblib/array.rb
parent
cf58d0d3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
61 deletions
+12
-61
mrblib/array.rb
mrblib/array.rb
+11
-0
mrblib/hash.rb
mrblib/hash.rb
+1
-0
src/array.c
src/array.c
+0
-61
No files found.
mrblib/array.rb
View file @
d9feed67
...
...
@@ -84,6 +84,17 @@ class Array
self
end
##
# Private method for Array creation.
#
# ISO 15.2.12.5.31 (x)
def
inspect
return
"[]"
if
self
.
size
==
0
"["
+
self
.
map
{
|
x
|
x
.
inspect
}.
join
(
", "
)
+
"]"
end
# ISO 15.2.12.5.32 (x)
alias
to_s
inspect
##
# Delete element with index +key+
def
delete
(
key
,
&
block
)
...
...
mrblib/hash.rb
View file @
d9feed67
...
...
@@ -142,6 +142,7 @@ class Hash
k
.
inspect
+
"=>"
+
v
.
inspect
}.
join
(
", "
)
+
"}"
end
# ISO 15.2.13.4.31 (x)
alias
to_s
inspect
# 1.8/1.9 Hash#reject! returns Hash; ISO says nothing.
...
...
src/array.c
View file @
d9feed67
...
...
@@ -983,65 +983,6 @@ mrb_ary_entry(mrb_value ary, mrb_int offset)
return
ary_elt
(
ary
,
offset
);
}
static
mrb_value
inspect_ary
(
mrb_state
*
mrb
,
mrb_value
ary
,
mrb_value
list
)
{
mrb_int
i
;
mrb_value
s
,
arystr
;
char
head
[]
=
{
'['
};
char
sep
[]
=
{
','
,
' '
};
char
tail
[]
=
{
']'
};
/* check recursive */
for
(
i
=
0
;
i
<
RARRAY_LEN
(
list
);
i
++
)
{
if
(
mrb_obj_equal
(
mrb
,
ary
,
RARRAY_PTR
(
list
)[
i
]))
{
return
mrb_str_new_lit
(
mrb
,
"[...]"
);
}
}
mrb_ary_push
(
mrb
,
list
,
ary
);
arystr
=
mrb_str_buf_new
(
mrb
,
64
);
mrb_str_buf_cat
(
mrb
,
arystr
,
head
,
sizeof
(
head
));
for
(
i
=
0
;
i
<
RARRAY_LEN
(
ary
);
i
++
)
{
int
ai
=
mrb_gc_arena_save
(
mrb
);
if
(
i
>
0
)
{
mrb_str_buf_cat
(
mrb
,
arystr
,
sep
,
sizeof
(
sep
));
}
if
(
mrb_array_p
(
RARRAY_PTR
(
ary
)[
i
]))
{
s
=
inspect_ary
(
mrb
,
RARRAY_PTR
(
ary
)[
i
],
list
);
}
else
{
s
=
mrb_inspect
(
mrb
,
RARRAY_PTR
(
ary
)[
i
]);
}
mrb_str_buf_cat
(
mrb
,
arystr
,
RSTRING_PTR
(
s
),
RSTRING_LEN
(
s
));
mrb_gc_arena_restore
(
mrb
,
ai
);
}
mrb_str_buf_cat
(
mrb
,
arystr
,
tail
,
sizeof
(
tail
));
mrb_ary_pop
(
mrb
,
list
);
return
arystr
;
}
/* 15.2.12.5.31 (x) */
/*
* call-seq:
* ary.to_s -> string
* ary.inspect -> string
*
* Creates a string representation of +self+.
*/
static
mrb_value
mrb_ary_inspect
(
mrb_state
*
mrb
,
mrb_value
ary
)
{
if
(
RARRAY_LEN
(
ary
)
==
0
)
return
mrb_str_new_lit
(
mrb
,
"[]"
);
return
inspect_ary
(
mrb
,
ary
,
mrb_ary_new
(
mrb
));
}
static
mrb_value
join_ary
(
mrb_state
*
mrb
,
mrb_value
ary
,
mrb_value
sep
,
mrb_value
list
)
{
...
...
@@ -1228,8 +1169,6 @@ mrb_init_array(mrb_state *mrb)
mrb_define_method
(
mrb
,
a
,
"slice"
,
mrb_ary_aget
,
MRB_ARGS_ANY
());
/* 15.2.12.5.29 */
mrb_define_method
(
mrb
,
a
,
"unshift"
,
mrb_ary_unshift_m
,
MRB_ARGS_ANY
());
/* 15.2.12.5.30 */
mrb_define_method
(
mrb
,
a
,
"inspect"
,
mrb_ary_inspect
,
MRB_ARGS_NONE
());
/* 15.2.12.5.31 (x) */
mrb_define_alias
(
mrb
,
a
,
"to_s"
,
"inspect"
);
/* 15.2.12.5.32 (x) */
mrb_define_method
(
mrb
,
a
,
"=="
,
mrb_ary_equal
,
MRB_ARGS_REQ
(
1
));
/* 15.2.12.5.33 (x) */
mrb_define_method
(
mrb
,
a
,
"eql?"
,
mrb_ary_eql
,
MRB_ARGS_REQ
(
1
));
/* 15.2.12.5.34 (x) */
mrb_define_method
(
mrb
,
a
,
"<=>"
,
mrb_ary_cmp
,
MRB_ARGS_REQ
(
1
));
/* 15.2.12.5.36 (x) */
...
...
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