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
d89cfca0
Commit
d89cfca0
authored
Dec 03, 2016
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Dec 03, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3315 from ksss/enumerator-with_index
Fix some incompatibility for Enumerator#with_index
parents
e673fbb3
2718fed1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
4 deletions
+13
-4
mrbgems/mruby-enumerator/mrblib/enumerator.rb
mrbgems/mruby-enumerator/mrblib/enumerator.rb
+10
-4
mrbgems/mruby-enumerator/test/enumerator.rb
mrbgems/mruby-enumerator/test/enumerator.rb
+3
-0
No files found.
mrbgems/mruby-enumerator/mrblib/enumerator.rb
View file @
d89cfca0
...
@@ -153,12 +153,18 @@ class Enumerator
...
@@ -153,12 +153,18 @@ class Enumerator
#
#
def
with_index
(
offset
=
0
)
def
with_index
(
offset
=
0
)
return
to_enum
:with_index
,
offset
unless
block_given?
return
to_enum
:with_index
,
offset
unless
block_given?
raise
TypeError
,
"no implicit conversion of
#{
offset
.
class
}
into Integer"
unless
offset
.
respond_to?
(
:to_int
)
offset
=
if
offset
.
nil?
0
elsif
offset
.
respond_to?
(
:to_int
)
offset
.
to_int
else
raise
TypeError
,
"no implicit conversion of
#{
offset
.
class
}
into Integer"
end
n
=
offset
.
to_int
-
1
n
=
offset
-
1
enumerator_block_call
do
|
i
|
enumerator_block_call
do
|
*
i
|
n
+=
1
n
+=
1
yield
[
i
,
n
]
yield
i
.
__svalue
,
n
end
end
end
end
...
...
mrbgems/mruby-enumerator/test/enumerator.rb
View file @
d89cfca0
...
@@ -50,6 +50,9 @@ end
...
@@ -50,6 +50,9 @@ end
assert
'Enumerator#with_index'
do
assert
'Enumerator#with_index'
do
assert_equal
([[
1
,
0
],[
2
,
1
],[
3
,
2
]],
@obj
.
to_enum
(
:foo
,
1
,
2
,
3
).
with_index
.
to_a
)
assert_equal
([[
1
,
0
],[
2
,
1
],[
3
,
2
]],
@obj
.
to_enum
(
:foo
,
1
,
2
,
3
).
with_index
.
to_a
)
assert_equal
([[
1
,
5
],[
2
,
6
],[
3
,
7
]],
@obj
.
to_enum
(
:foo
,
1
,
2
,
3
).
with_index
(
5
).
to_a
)
assert_equal
([[
1
,
5
],[
2
,
6
],[
3
,
7
]],
@obj
.
to_enum
(
:foo
,
1
,
2
,
3
).
with_index
(
5
).
to_a
)
a
=
[]
@obj
.
to_enum
(
:foo
,
1
,
2
,
3
).
with_index
(
10
).
with_index
(
20
)
{
|*
i
|
a
<<
i
}
assert_equal
[[[
1
,
10
],
20
],
[[
2
,
11
],
21
],
[[
3
,
12
],
22
]],
a
end
end
assert
'Enumerator#with_index nonnum offset'
do
assert
'Enumerator#with_index nonnum offset'
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