Skip to content

Commit

Permalink
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -1098,12 +1098,14 @@ public static IRubyObject each_slice19(ThreadContext context, IRubyObject self,

@JRubyMethod(name = "each_slice")
public static IRubyObject each_slice(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
return block.isGiven() ? each_sliceCommon(context, self, arg, block) :
int size = (int) RubyNumeric.num2long(arg);
if (size <= 0) throw context.runtime.newArgumentError("invalid size");

return block.isGiven() ? each_sliceCommon(context, self, size, block) :
enumeratorizeWithSize(context, self, "each_slice", new IRubyObject[]{arg}, eachSliceSizeFn(context, self));
}

static IRubyObject each_sliceCommon(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
final int size = RubyNumeric.num2int(arg);
static IRubyObject each_sliceCommon(ThreadContext context, IRubyObject self, final int size, final Block block) {
final Ruby runtime = context.runtime;
if (size <= 0) throw runtime.newArgumentError("invalid slice size");

5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
@@ -422,7 +422,10 @@ public IRubyObject each_slice19(ThreadContext context, IRubyObject arg, final Bl

@JRubyMethod(name = "each_slice")
public IRubyObject each_slice(ThreadContext context, IRubyObject arg, final Block block) {
return block.isGiven() ? RubyEnumerable.each_sliceCommon(context, this, arg, block) : enumeratorize(context.runtime, getType(), this, "each_slice", arg);
int size = (int) RubyNumeric.num2long(arg);
if (size <= 0) throw context.runtime.newArgumentError("invalid size");

return block.isGiven() ? RubyEnumerable.each_sliceCommon(context, this, size, block) : enumeratorize(context.runtime, getType(), this, "each_slice", arg);
}

@Deprecated
1 change: 0 additions & 1 deletion spec/tags/ruby/core/enumerable/each_slice_tags.txt

This file was deleted.

0 comments on commit 93d52c0

Please sign in to comment.