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
9262a9f4
Commit
9262a9f4
authored
Mar 19, 2013
by
skandhas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add Enumerable#drop_while
parent
ab79941c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
mrbgems/mruby-enum-ext/mrblib/enum.rb
mrbgems/mruby-enum-ext/mrblib/enum.rb
+20
-0
mrbgems/mruby-enum-ext/test/enum.rb
mrbgems/mruby-enum-ext/test/enum.rb
+5
-0
No files found.
mrbgems/mruby-enum-ext/mrblib/enum.rb
View file @
9262a9f4
...
...
@@ -20,5 +20,25 @@ module Enumerable
self
.
each
{
|
e
|
n
==
0
?
ary
<<
e
:
n
-=
1
}
ary
end
##
# call-seq:
# enum.drop_while {|arr| block } -> array
#
# Drops elements up to, but not including, the first element for
# which the block returns +nil+ or +false+ and returns an array
# containing the remaining elements.
#
# a = [1, 2, 3, 4, 5, 0]
# a.drop_while {|i| i < 3 } #=> [3, 4, 5, 0]
def
drop_while
(
&
block
)
ary
,
state
=
[],
false
self
.
each
do
|
e
|
state
=
true
if
!
state
and
!
block
.
call
(
e
)
ary
<<
e
if
state
end
ary
end
end
mrbgems/mruby-enum-ext/test/enum.rb
View file @
9262a9f4
...
...
@@ -8,3 +8,8 @@ assert("Enumrable#drop") do
assert_equal
a
.
drop
(
6
),
[]
end
assert
(
"Enumrable#drop_while"
)
do
a
=
[
1
,
2
,
3
,
4
,
5
,
0
]
assert_equal
a
.
drop_while
{
|
i
|
i
<
3
},
[
3
,
4
,
5
,
0
]
end
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