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
a98359fa
Commit
a98359fa
authored
Jan 01, 2019
by
dearblue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add enumerator chain feature (CRuby-2.6 compatible)
- Enumerator::Chain - Enumerable#chain - Enumerable#+
parent
3e59f25e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
0 deletions
+66
-0
mrbgems/mruby-enum-chain/mrbgem.rake
mrbgems/mruby-enum-chain/mrbgem.rake
+6
-0
mrbgems/mruby-enum-chain/mrblib/chain.rb
mrbgems/mruby-enum-chain/mrblib/chain.rb
+60
-0
No files found.
mrbgems/mruby-enum-chain/mrbgem.rake
0 → 100644
View file @
a98359fa
MRuby
::
Gem
::
Specification
.
new
(
'mruby-enum-chain'
)
do
|
spec
|
spec
.
license
=
'MIT'
spec
.
author
=
'mruby developers'
spec
.
summary
=
'Enumerator::Chain class'
spec
.
add_dependency
(
'mruby-enumerator'
,
:core
=>
'mruby-enumerator'
)
end
mrbgems/mruby-enum-chain/mrblib/chain.rb
0 → 100644
View file @
a98359fa
##
# chain.rb Enumerator::Chain class
# See Copyright Notice in mruby.h
module
Enumerable
def
chain
(
*
args
)
Enumerator
::
Chain
.
new
(
self
,
*
args
)
end
def
+
(
other
)
Enumerator
::
Chain
.
new
(
self
,
other
)
end
end
class
Enumerator
class
Chain
include
Enumerable
def
initialize
(
*
args
)
@enums
=
args
end
def
initialize_copy
(
orig
)
@enums
=
orig
.
__copy_enums
end
def
each
(
&
block
)
return
to_enum
unless
block_given?
@enums
.
each
{
|
e
|
e
.
each
(
&
block
)
}
self
end
def
size
@enums
.
reduce
(
0
)
do
|
a
,
e
|
return
nil
unless
e
.
respond_to?
(
:size
)
a
+
e
.
size
end
end
def
rewind
@enums
.
reverse_each
do
|
e
|
e
.
rewind
if
e
.
respond_to?
(
:rewind
)
end
self
end
def
inspect
"#<
#{
self
.
class
}
:
#{
@enums
.
inspect
}
>"
end
def
__copy_enums
@enums
.
each_with_object
([])
do
|
e
,
a
|
a
<<
e
.
clone
end
end
end
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