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
59464f35
Unverified
Commit
59464f35
authored
Jan 21, 2020
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jan 21, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4935 from mimaki/delete-duplicated-Array-delete_if
Delete duplicated `Array#delete_if`.
parents
f7abda14
7d9a49ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
44 deletions
+0
-44
mrbgems/mruby-array-ext/mrblib/array.rb
mrbgems/mruby-array-ext/mrblib/array.rb
+0
-31
mrbgems/mruby-array-ext/test/array.rb
mrbgems/mruby-array-ext/test/array.rb
+0
-13
No files found.
mrbgems/mruby-array-ext/mrblib/array.rb
View file @
59464f35
...
...
@@ -686,37 +686,6 @@ class Array
satisfied
?
low
:
nil
end
##
# call-seq:
# ary.delete_if { |item| block } -> ary
# ary.delete_if -> Enumerator
#
# Deletes every element of +self+ for which block evaluates to +true+.
#
# The array is changed instantly every time the block is called, not after
# the iteration is over.
#
# See also Array#reject!
#
# If no block is given, an Enumerator is returned instead.
#
# scores = [ 97, 42, 75 ]
# scores.delete_if {|score| score < 80 } #=> [97]
def
delete_if
(
&
block
)
return
to_enum
:delete_if
unless
block
idx
=
0
while
idx
<
self
.
size
do
if
block
.
call
(
self
[
idx
])
self
.
delete_at
(
idx
)
else
idx
+=
1
end
end
self
end
##
# call-seq:
# ary.keep_if { |item| block } -> ary
...
...
mrbgems/mruby-array-ext/test/array.rb
View file @
59464f35
...
...
@@ -299,19 +299,6 @@ end
#assert("Array#bsearch_index") do
#end
assert
(
"Array#delete_if"
)
do
a
=
[
1
,
2
,
3
,
4
,
5
]
assert_equal
[
1
,
2
,
3
,
4
,
5
],
a
.
delete_if
{
false
}
assert_equal
[
1
,
2
,
3
,
4
,
5
],
a
a
=
[
1
,
2
,
3
,
4
,
5
]
assert_equal
[],
a
.
delete_if
{
true
}
assert_equal
[],
a
a
=
[
1
,
2
,
3
,
4
,
5
]
assert_equal
[
1
,
2
,
3
],
a
.
delete_if
{
|
val
|
val
>
3
}
end
assert
(
"Array#keep_if"
)
do
a
=
[
1
,
2
,
3
,
4
,
5
]
assert_equal
[
1
,
2
,
3
,
4
,
5
],
a
.
keep_if
{
true
}
...
...
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