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
39c036ab
Commit
39c036ab
authored
Apr 24, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2115 from ksss/ary-fill
Fix Array#fill bug and behavior
parents
fdcea862
4652c7ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
11 deletions
+32
-11
mrbgems/mruby-array-ext/mrblib/array.rb
mrbgems/mruby-array-ext/mrblib/array.rb
+13
-9
mrbgems/mruby-array-ext/test/array.rb
mrbgems/mruby-array-ext/test/array.rb
+19
-2
No files found.
mrbgems/mruby-array-ext/mrblib/array.rb
View file @
39c036ab
...
...
@@ -313,7 +313,7 @@ class Array
def
fill
(
arg0
=
nil
,
arg1
=
nil
,
arg2
=
nil
,
&
block
)
if
arg0
==
nil
&&
arg1
==
nil
&&
arg2
==
nil
&&
!
block
raise
ArgumentError
,
"wrong number of arguments (0 for 1..3)"
raise
ArgumentError
,
"wrong number of arguments (0 for 1..3)"
end
beg
=
len
=
0
...
...
@@ -323,11 +323,13 @@ class Array
# ary.fill { |index| block } -> ary
beg
=
0
len
=
self
.
size
elsif
arg0
!=
nil
&&
arg0
.
respond_to?
(
:begin
)
&&
arg0
.
respond_to?
(
:end
)
elsif
arg0
!=
nil
&&
arg0
.
kind_of?
(
Range
)
# ary.fill(range) { |index| block } -> ary
beg
=
arg0
.
begin
beg
+=
self
.
size
if
beg
<
0
len
=
arg0
.
end
-
beg
+
1
len
=
arg0
.
end
len
+=
self
.
size
if
len
<
0
len
+=
1
unless
arg0
.
exclude_end?
elsif
arg0
!=
nil
# ary.fill(start [, length] ) { |index| block } -> ary
beg
=
arg0
...
...
@@ -342,20 +344,22 @@ class Array
if
arg0
!=
nil
&&
arg1
==
nil
&&
arg2
==
nil
# ary.fill(obj) -> ary
beg
=
0
len
=
self
.
size
elsif
arg0
!=
nil
&&
arg1
!=
nil
&&
arg1
.
respond_to?
(
:begin
)
&&
arg1
.
respond_to?
(
:end
)
# ary.fill(obj, range ) -> ary
len
=
self
.
size
elsif
arg0
!=
nil
&&
arg1
!=
nil
&&
arg1
.
kind_of?
(
Range
)
# ary.fill(obj, range ) -> ary
beg
=
arg1
.
begin
len
=
arg1
.
end
-
beg
+
1
beg
+=
self
.
size
if
beg
<
0
len
=
arg1
.
end
len
+=
self
.
size
if
len
<
0
len
+=
1
unless
arg1
.
exclude_end?
elsif
arg0
!=
nil
&&
arg1
!=
nil
# ary.fill(obj, start [, length]) -> ary
beg
=
arg1
beg
+=
self
.
size
if
beg
<
0
if
arg2
==
nil
if
arg2
==
nil
len
=
self
.
size
else
len
=
arg1
+
arg2
len
=
beg
+
arg2
end
end
end
...
...
mrbgems/mruby-array-ext/test/array.rb
View file @
39c036ab
...
...
@@ -125,14 +125,31 @@ end
assert
(
"Array#fill"
)
do
a
=
[
"a"
,
"b"
,
"c"
,
"d"
]
assert_equal
[
"x"
,
"x"
,
"x"
,
"x"
],
a
.
fill
(
"x"
)
assert_equal
[
"x"
,
"x"
,
"x"
,
"w"
],
a
.
fill
(
"w"
,
-
1
)
assert_equal
[
"x"
,
"x"
,
"x"
,
"w"
],
a
.
fill
(
"w"
,
-
1
)
assert_equal
[
"x"
,
"x"
,
"z"
,
"z"
],
a
.
fill
(
"z"
,
2
,
2
)
assert_equal
[
"y"
,
"y"
,
"z"
,
"z"
],
a
.
fill
(
"y"
,
0
..
1
)
assert_equal
[
0
,
1
,
4
,
9
],
a
.
fill
{
|
i
|
i
*
i
}
assert_equal
[
0
,
1
,
4
,
9
],
a
.
fill
{
|
i
|
i
*
i
}
assert_equal
[
0
,
1
,
8
,
27
],
a
.
fill
(
-
2
)
{
|
i
|
i
*
i
*
i
}
assert_equal
[
0
,
2
,
3
,
27
],
a
.
fill
(
1
,
2
)
{
|
i
|
i
+
1
}
assert_equal
[
1
,
2
,
3
,
27
],
a
.
fill
(
0
..
1
)
{
|
i
|
i
+
1
}
assert_raise
(
ArgumentError
)
{
a
.
fill
}
assert_equal
([
0
,
1
,
2
,
3
,
-
1
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
-
1
,
-
2
,
1
))
assert_equal
([
0
,
1
,
2
,
3
,
-
1
,
-
1
,
-
1
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
-
1
,
-
2
,
3
))
assert_equal
([
0
,
1
,
2
,
-
1
,
-
1
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
-
1
,
3
..
4
))
assert_equal
([
0
,
1
,
2
,
-
1
,
4
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
-
1
,
3
...
4
))
assert_equal
([
0
,
1
,
-
1
,
-
1
,
-
1
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
-
1
,
2
..-
2
))
assert_equal
([
0
,
1
,
-
1
,
-
1
,
4
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
-
1
,
2
...-
2
))
assert_equal
([
0
,
1
,
2
,
13
,
14
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
3
..
4
){
|
i
|
i
+
10
})
assert_equal
([
0
,
1
,
2
,
13
,
4
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
3
...
4
){
|
i
|
i
+
10
})
assert_equal
([
0
,
1
,
12
,
13
,
14
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
2
..-
2
){
|
i
|
i
+
10
})
assert_equal
([
0
,
1
,
12
,
13
,
4
,
5
],
[
0
,
1
,
2
,
3
,
4
,
5
].
fill
(
2
...-
2
){
|
i
|
i
+
10
})
assert_equal
[
1
,
2
,
3
,
4
,
'x'
,
'x'
],
[
1
,
2
,
3
,
4
,
5
,
6
].
fill
(
'x'
,
-
2
..-
1
)
assert_equal
[
1
,
2
,
3
,
4
,
'x'
,
6
],
[
1
,
2
,
3
,
4
,
5
,
6
].
fill
(
'x'
,
-
2
...-
1
)
assert_equal
[
1
,
2
,
3
,
4
,
5
,
6
],
[
1
,
2
,
3
,
4
,
5
,
6
].
fill
(
'x'
,
-
2
...-
2
)
assert_equal
[
1
,
2
,
3
,
4
,
'x'
,
6
],
[
1
,
2
,
3
,
4
,
5
,
6
].
fill
(
'x'
,
-
2
..-
2
)
assert_equal
[
1
,
2
,
3
,
4
,
5
,
6
],
[
1
,
2
,
3
,
4
,
5
,
6
].
fill
(
'x'
,
-
2
..
0
)
end
assert
(
"Array#reverse_each"
)
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