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
747059a7
Commit
747059a7
authored
Sep 19, 2018
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed `to_ary` conversion method.
parent
b6c5e501
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
59 deletions
+29
-59
include/mruby/array.h
include/mruby/array.h
+1
-0
mrbgems/mruby-array-ext/mrblib/array.rb
mrbgems/mruby-array-ext/mrblib/array.rb
+1
-10
mrbgems/mruby-array-ext/test/array.rb
mrbgems/mruby-array-ext/test/array.rb
+0
-16
mrbgems/mruby-enumerator/mrblib/enumerator.rb
mrbgems/mruby-enumerator/mrblib/enumerator.rb
+1
-3
mrbgems/mruby-kernel-ext/src/kernel.c
mrbgems/mruby-kernel-ext/src/kernel.c
+2
-7
src/array.c
src/array.c
+5
-22
src/class.c
src/class.c
+2
-1
src/object.c
src/object.c
+17
-0
No files found.
include/mruby/array.h
View file @
747059a7
...
...
@@ -199,6 +199,7 @@ MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val
* @param other The array to replace it with.
*/
MRB_API
void
mrb_ary_replace
(
mrb_state
*
mrb
,
mrb_value
self
,
mrb_value
other
);
MRB_API
mrb_value
mrb_array_type
(
mrb_state
*
mrb
,
mrb_value
self
);
MRB_API
mrb_value
mrb_check_array_type
(
mrb_state
*
mrb
,
mrb_value
self
);
/*
...
...
mrbgems/mruby-array-ext/mrblib/array.rb
View file @
747059a7
# coding: cp932
class
Array
##
# call-seq:
...
...
@@ -757,16 +758,6 @@ class Array
nil
end
##
# call-seq:
# ary.to_ary -> ary
#
# Returns +self+.
#
def
to_ary
self
end
##
# call-seq:
# ary.dig(idx, ...) -> object
...
...
mrbgems/mruby-array-ext/test/array.rb
View file @
747059a7
...
...
@@ -323,27 +323,11 @@ assert('Array#to_h') do
assert_raise
(
ArgumentError
)
{
[[
1
]].
to_h
}
end
assert
(
'Array#to_h (Modified)'
)
do
class
A
def
to_ary
$a
.
clear
nil
end
end
$a
=
[
A
.
new
]
assert_raise
(
TypeError
)
{
$a
.
to_h
}
end
assert
(
"Array#index (block)"
)
do
assert_nil
(
1
..
10
).
to_a
.
index
{
|
i
|
i
%
5
==
0
and
i
%
7
==
0
}
assert_equal
34
,
(
1
..
100
).
to_a
.
index
{
|
i
|
i
%
5
==
0
and
i
%
7
==
0
}
end
assert
(
"Array#to_ary"
)
do
assert_equal
[],
[].
to_ary
assert_equal
[
1
,
2
,
3
],
[
1
,
2
,
3
].
to_ary
end
assert
(
"Array#dig"
)
do
h
=
[[[
1
]],
0
]
assert_equal
(
1
,
h
.
dig
(
0
,
0
,
0
))
...
...
mrbgems/mruby-enumerator/mrblib/enumerator.rb
View file @
747059a7
...
...
@@ -621,9 +621,7 @@ module Enumerable
# use Enumerator to use infinite sequence
def
zip
(
*
args
,
&
block
)
args
=
args
.
map
do
|
a
|
if
a
.
respond_to?
(
:to_ary
)
a
.
to_ary
.
to_enum
(
:each
)
elsif
a
.
respond_to?
(
:each
)
if
a
.
respond_to?
(
:each
)
a
.
to_enum
(
:each
)
else
raise
TypeError
,
"wrong argument type
#{
a
.
class
}
(must respond to :each)"
...
...
mrbgems/mruby-kernel-ext/src/kernel.c
View file @
747059a7
...
...
@@ -161,9 +161,7 @@ mrb_f_string(mrb_state *mrb, mrb_value self)
* call-seq:
* Array(arg) -> array
*
* Returns +arg+ as an Array.
*
* First tries to call Array#to_ary on +arg+, then Array#to_a.
* Returns +arg+ as an Array using to_a method.
*
* Array(1..5) #=> [1, 2, 3, 4, 5]
*
...
...
@@ -174,10 +172,7 @@ mrb_f_array(mrb_state *mrb, mrb_value self)
mrb_value
arg
,
tmp
;
mrb_get_args
(
mrb
,
"o"
,
&
arg
);
tmp
=
mrb_check_convert_type
(
mrb
,
arg
,
MRB_TT_ARRAY
,
"Array"
,
"to_ary"
);
if
(
mrb_nil_p
(
tmp
))
{
tmp
=
mrb_check_convert_type
(
mrb
,
arg
,
MRB_TT_ARRAY
,
"Array"
,
"to_a"
);
}
tmp
=
mrb_check_convert_type
(
mrb
,
arg
,
MRB_TT_ARRAY
,
"Array"
,
"to_a"
);
if
(
mrb_nil_p
(
tmp
))
{
return
mrb_ary_new_from_values
(
mrb
,
1
,
&
arg
);
}
...
...
src/array.c
View file @
747059a7
...
...
@@ -1058,7 +1058,7 @@ mrb_ary_rindex_m(mrb_state *mrb, mrb_value self)
MRB_API
mrb_value
mrb_ary_splat
(
mrb_state
*
mrb
,
mrb_value
v
)
{
mrb_value
a
,
recv_class
;
mrb_value
a
;
if
(
mrb_array_p
(
v
))
{
return
v
;
...
...
@@ -1069,22 +1069,11 @@ mrb_ary_splat(mrb_state *mrb, mrb_value v)
}
a
=
mrb_funcall
(
mrb
,
v
,
"to_a"
,
0
);
if
(
mrb_array_p
(
a
))
{
return
a
;
}
else
if
(
mrb_nil_p
(
a
))
{
if
(
mrb_nil_p
(
a
))
{
return
mrb_ary_new_from_values
(
mrb
,
1
,
&
v
);
}
else
{
recv_class
=
mrb_obj_value
(
mrb_obj_class
(
mrb
,
v
));
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"can't convert %S to Array (%S#to_a gives %S)"
,
recv_class
,
recv_class
,
mrb_obj_value
(
mrb_obj_class
(
mrb
,
a
))
);
/* not reached */
return
mrb_undef_value
();
}
mrb_array_type
(
mrb
,
a
);
return
a
;
}
static
mrb_value
...
...
@@ -1121,12 +1110,6 @@ mrb_ary_empty_p(mrb_state *mrb, mrb_value self)
return
mrb_bool_value
(
ARY_LEN
(
a
)
==
0
);
}
MRB_API
mrb_value
mrb_check_array_type
(
mrb_state
*
mrb
,
mrb_value
ary
)
{
return
mrb_check_convert_type
(
mrb
,
ary
,
MRB_TT_ARRAY
,
"Array"
,
"to_ary"
);
}
MRB_API
mrb_value
mrb_ary_entry
(
mrb_value
ary
,
mrb_int
offset
)
{
...
...
@@ -1180,7 +1163,7 @@ join_ary(mrb_state *mrb, mrb_value ary, mrb_value sep, mrb_value list)
val
=
tmp
;
goto
str_join
;
}
tmp
=
mrb_check_
convert_type
(
mrb
,
val
,
MRB_TT_ARRAY
,
"Array"
,
"to_ary"
);
tmp
=
mrb_check_
array_type
(
mrb
,
val
);
if
(
!
mrb_nil_p
(
tmp
))
{
val
=
tmp
;
goto
ary_join
;
...
...
src/class.c
View file @
747059a7
...
...
@@ -520,7 +520,8 @@ to_str(mrb_state *mrb, mrb_value val)
static
mrb_value
to_ary
(
mrb_state
*
mrb
,
mrb_value
val
)
{
return
check_type
(
mrb
,
val
,
MRB_TT_ARRAY
,
"Array"
,
"to_ary"
);
CHECK_TYPE
(
mrb
,
val
,
MRB_TT_ARRAY
,
"Array"
);
return
val
;
}
static
mrb_value
...
...
src/object.c
View file @
747059a7
...
...
@@ -606,6 +606,23 @@ mrb_check_string_type(mrb_state *mrb, mrb_value str)
return
str
;
}
MRB_API
mrb_value
mrb_array_type
(
mrb_state
*
mrb
,
mrb_value
ary
)
{
if
(
!
mrb_array_p
(
ary
))
{
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"%S cannot be converted to Array"
,
inspect_type
(
mrb
,
ary
));
}
return
ary
;
}
MRB_API
mrb_value
mrb_check_array_type
(
mrb_state
*
mrb
,
mrb_value
ary
)
{
if
(
!
mrb_array_p
(
ary
))
return
mrb_nil_value
();
return
ary
;
}
MRB_API
mrb_value
mrb_inspect
(
mrb_state
*
mrb
,
mrb_value
obj
)
{
...
...
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