Skip to content

Commit f151e85

Browse files
committedNov 1, 2014
Fixes for Enumerator#with_index #550
1 parent e42c02c commit f151e85

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
* Add initial support for Module#autoload.
2323

24+
* Fix `Enumerator#with_index`.
25+
2426
## 0.6.2 2014-04-25
2527

2628
* Added Range#size

‎opal/corelib/enumerator.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def with_index(offset = 0, &block)
5959
return enum_for :with_index, offset unless block
6060

6161
%x{
62-
var result
62+
var result, index = 0;
6363
6464
self.$each.$$p = function() {
6565
var param = #{Opal.destructure(`arguments`)},
@@ -78,6 +78,8 @@ def with_index(offset = 0, &block)
7878
if (result !== undefined) {
7979
return result;
8080
}
81+
82+
return nil;
8183
}
8284
end
8385

‎spec/filters/bugs/enumerator.rb

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
opal_filter "Enumerator" do
22
fails "Enumerator#each requires multiple arguments" # arity issue
3+
4+
fails "Enumerator#with_index returns the object being enumerated when given a block"
5+
fails "Enumerator#with_index numbers indices from the given index when given an offset but no block"
6+
fails "Enumerator#with_index numbers indices from the given index when given an offset and block"
7+
fails "Enumerator#with_index converts non-numeric arguments to Integer via #to_int"
8+
fails "Enumerator#with_index coerces the given numeric argument to an Integer"
9+
fails "Enumerator#with_index accepts negative argument"
310
end

‎spec/rubyspecs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ corelib/core/enumerator/each_spec
3636
corelib/core/enumerator/new_spec
3737
corelib/core/enumerator/next_spec
3838
corelib/core/enumerator/rewind_spec
39+
corelib/core/enumerator/with_index_spec
3940

4041
corelib/core/kernel/comparison_spec
4142
corelib/core/kernel/eql_spec

0 commit comments

Comments
 (0)
Please sign in to comment.