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
ca1bc529
Commit
ca1bc529
authored
Mar 28, 2014
by
Jun Hiroe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add to_enum unless block
parent
03fa4576
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
mrbgems/mruby-enum-ext/mrblib/enum.rb
mrbgems/mruby-enum-ext/mrblib/enum.rb
+22
-0
No files found.
mrbgems/mruby-enum-ext/mrblib/enum.rb
View file @
ca1bc529
...
...
@@ -25,15 +25,20 @@ module Enumerable
##
# call-seq:
# enum.drop_while {|arr| block } -> array
# enum.drop_while -> an_enumerator
#
# 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.
#
# If no block is given, an enumerator is returned instead.
#
# a = [1, 2, 3, 4, 5, 0]
# a.drop_while {|i| i < 3 } #=> [3, 4, 5, 0]
def
drop_while
(
&
block
)
return
to_enum
:drop_while
unless
block_given?
ary
,
state
=
[],
false
self
.
each
do
|*
val
|
state
=
true
if
!
state
and
!
block
.
call
(
*
val
)
...
...
@@ -67,15 +72,19 @@ module Enumerable
##
# call-seq:
# enum.take_while {|arr| block } -> array
# enum.take_while -> an_enumerator
#
# Passes elements to the block until the block returns +nil+ or +false+,
# then stops iterating and returns an array of all prior elements.
#
# If no block is given, an enumerator is returned instead.
#
# a = [1, 2, 3, 4, 5, 0]
# a.take_while {|i| i < 3 } #=> [1, 2]
def
take_while
(
&
block
)
return
to_enum
:take_while
unless
block_given?
ary
=
[]
self
.
each
do
|*
val
|
return
ary
unless
block
.
call
(
*
val
)
...
...
@@ -149,6 +158,7 @@ module Enumerable
##
# call-seq:
# enum.group_by {| obj | block } -> a_hash
# enum.group_by -> an_enumerator
#
# Returns a hash, which keys are evaluated result from the
# block, and values are arrays of elements in <i>enum</i>
...
...
@@ -157,6 +167,8 @@ module Enumerable
# (1..6).group_by {|i| i%3} #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}
def
group_by
(
&
block
)
return
to_enum
:group_by
unless
block_given?
h
=
{}
self
.
each
do
|*
val
|
key
=
block
.
call
(
*
val
)
...
...
@@ -169,10 +181,16 @@ module Enumerable
##
# call-seq:
# enum.sort_by { |obj| block } -> array
# enum.sort_by -> an_enumerator
#
# Sorts <i>enum</i> using a set of keys generated by mapping the
# values in <i>enum</i> through the given block.
#
# If no block is given, an enumerator is returned instead.
def
sort_by
(
&
block
)
return
to_enum
:sort_by
unless
block_given?
ary
=
[]
orig
=
[]
self
.
each_with_index
{
|
e
,
i
|
...
...
@@ -393,6 +411,8 @@ module Enumerable
# %w(albatross dog horse).minmax_by { |x| x.length } #=> ["dog", "albatross"]
def
minmax_by
(
&
block
)
return
to_enum
:minmax_by
unless
block_given?
max
=
nil
max_cmp
=
nil
min
=
nil
...
...
@@ -522,6 +542,8 @@ module Enumerable
#
def
reverse_each
(
&
block
)
return
to_enum
:reverse_each
unless
block_given?
ary
=
self
.
to_a
i
=
ary
.
size
-
1
while
i
>=
0
...
...
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