Skip to content


Browse files Browse the repository at this point in the history
Implement Enumerable#reverse_each
  • Loading branch information
adambeynon committed Dec 14, 2013
1 parent 7dae682 commit aeee689
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions
Expand Up @@ -86,8 +86,8 @@
* Fix various `Struct` methods. Fixed `#each` and `#each_pair` to return
self. Add `Struct.[]` as synonym for ``.

* Implemented some `Enumerable` methods: `#collect_concat`, `#flat_map` and
* Implemented some `Enumerable` methods: `#collect_concat`, `#flat_map`,
`#reject` and `#reverse_each`.

## 0.5.5 2013-11-25

Expand Down
19 changes: 18 additions & 1 deletion opal/corelib/enumerable.rb
Expand Up @@ -970,8 +970,25 @@ def reject(&block)
return result;

def reverse_each(&block)
raise NotImplementedError
return enum_for :reverse_each unless block_given?

var result = [];
self.$each._p = function() {
for (var i = result.length - 1; i >= 0; i--) {
$opal.$yieldX(block, result[i]);
return result;

alias select find_all
Expand Down
2 changes: 0 additions & 2 deletions spec/opal/filters/bugs/enumerable.rb
Expand Up @@ -53,8 +53,6 @@
fails "Enumerable#partition returns two arrays, the first containing elements for which the block is true, the second containing the rest"

fails "Enumerable#reverse_each gathers whole arrays as elements when each yields multiple"
fails "Enumerable#reverse_each returns an Enumerator if no block given"
fails "Enumerable#reverse_each traverses enum in reverse order and pass each element to block"

fails "Enumerable#sort gathers whole arrays as elements when each yields multiple"
fails "Enumerable#sort raises an error if objects can't be compared"
Expand Down

0 comments on commit aeee689

Please sign in to comment.