Skip to content

Commit

Permalink
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 1 addition & 5 deletions kernel/common/enumerable.rb
Original file line number Diff line number Diff line change
@@ -424,11 +424,7 @@ def each_cons(num)
end

def each_slice(slice_size)
unless block_given?
enum = to_enum(:each_slice, slice_size)
enum.size = Proc.new { enum.count }
return enum
end
return to_enum(:each_slice, slice_size) unless block_given?

n = Rubinius::Type.coerce_to_collection_index slice_size
raise ArgumentError, "invalid slice size: #{n}" if n <= 0
13 changes: 7 additions & 6 deletions kernel/common/enumerator.rb
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ def initialize(receiver_or_size=undefined, method_name=:each, *method_args, &blo
raise ArgumentError, "Enumerator#initialize requires a block when called without arguments"
end

size = receiver_or_size
receiver = receiver_or_size
end

@@ -149,11 +148,13 @@ def rewind
end

def size
@size.kind_of?(Proc) ? @size.call : @size
end

def size=(size)
@size = size
if @size.kind_of?(Proc)
@size.call
elsif @size
@size
else
count
end
end

def with_index(offset=0)

0 comments on commit 76a23a6

Please sign in to comment.