Skip to content

Commit

Permalink
Return enumerators in various Enumerable methods to fix some specs
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Sep 20, 2013
1 parent 1f1b40a commit 0e8a98a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 9 additions & 1 deletion corelib/enumerable.rb
Expand Up @@ -214,6 +214,8 @@ def drop(number)
end

def drop_while(&block)
return enum_for :drop_while unless block_given?

%x{
var result = [];
Expand Down Expand Up @@ -241,6 +243,8 @@ def drop_while(&block)
end

def each_slice(n, &block)
return enum_for :each_slice, n unless block_given?

%x{
var all = [];
Expand Down Expand Up @@ -291,7 +295,7 @@ def each_with_index(&block)
end

def each_with_object(object = undefined, &block)
return enum_for :each_with_object unless block_given?
return enum_for :each_with_object, object unless block_given?

%x{
#{self}.$each._p = function() {
Expand Down Expand Up @@ -482,6 +486,8 @@ def grep(pattern, &block)
end

def group_by(&block)
return enum_for :group_by unless block_given?

hash = Hash.new { |h, k| h[k] = [] }

each do |el|
Expand Down Expand Up @@ -659,6 +665,8 @@ def none?(&block)
end

def sort_by(&block)
return enum_for :sort_by unless block_given?

map { |*f|
# FIXME: this should probably belongs to somewhere more
f = `#{f}.length === 1 ? #{f}[0] : #{f}`
Expand Down
7 changes: 0 additions & 7 deletions spec/filters/bugs/enumerable.rb
Expand Up @@ -3,7 +3,6 @@
fails "Enumerable#drop passed a number n as an argument tries to convert n to an Integer using #to_int"
fails "Enumerable#drop passed a number n as an argument raises a TypeError when the passed n can be coerced to Integer"

fails "Enumerable#drop_while returns an Enumerator if no block given"
fails "Enumerable#drop_while passes elements to the block until the first false"
fails "Enumerable#drop_while will only go through what's needed"
fails "Enumerable#drop_while gathers whole arrays as elements when each yields multiple"
Expand All @@ -12,21 +11,15 @@
fails "Enumerable#each_slice raises an Argument Error if there is not a single parameter > 0"
fails "Enumerable#each_slice yields only as much as needed"
fails "Enumerable#each_slice gathers whole arrays as elements when each yields multiple"
fails "Enumerable#each_slice returns an enumerator if no block"

fails "Enumerable#each_with_index provides each element to the block"
fails "Enumerable#each_with_index provides each element to the block and its index"
fails "Enumerable#each_with_index binds splat arguments properly"
fails "Enumerable#each_with_index passes extra parameters to each"

fails "Enumerable#each_with_object returns an enumerator if no block"

fails "Enumerable#find_index gathers initial args as elements when each yields multiple"
fails "Enumerable#grep can use $~ in the block when used with a Regexp"

fails "Enumerable#group_by returns a hash without default_proc"
fails "Enumerable#group_by returns an Enumerator if called without a block"
fails "Enumerable#group_by gathers whole arrays as elements when each yields multiple"

fails "Enumerable#sort_by returns an Enumerator when a block is not supplied"
end

0 comments on commit 0e8a98a

Please sign in to comment.