Skip to content

Commit

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

@JRubyMethod(name = "each_cons")
public static IRubyObject each_cons(ThreadContext context, IRubyObject self, IRubyObject arg, final Block block) {
return block.isGiven() ? each_consCommon(context, self, arg, block) : enumeratorizeWithSize(context, self, "each_cons", new IRubyObject[] { arg }, eachConsSizeFn(context, self));
int size = (int) RubyNumeric.num2long(arg);
if (size <= 0) throw context.runtime.newArgumentError("invalid size");
return block.isGiven() ? each_consCommon(context, self, size, block) : enumeratorizeWithSize(context, self, "each_cons", new IRubyObject[] { arg }, eachConsSizeFn(context, self));
}

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

final RubyArray result = runtime.newArray(size);

RubyEnumerable.callEach(runtime, context, self, Signature.OPTIONAL, new BlockCallback() {
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
@@ -432,7 +432,9 @@ public IRubyObject each_cons19(ThreadContext context, IRubyObject arg, final Blo

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

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

This file was deleted.

0 comments on commit 237fbf9

Please sign in to comment.