Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8d68c0dc43d4
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 53ff45953871
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Jun 29, 2015

  1. we shall fail on each_with_object without args

    (just like MRI 2.2 & as used to on JRuby 1.7.x)
    kares committed Jun 29, 2015
    Copy the full SHA
    242663f View commit details
  2. Copy the full SHA
    dc12f66 View commit details
  3. Copy the full SHA
    e466e13 View commit details
  4. handle each_with_object (lambda) block arg like MRI

    since `lambda{ |str, hash| }` was no longer working
    (as in JRuby 1.7.x) fixes #2943
    kares committed Jun 29, 2015
    Copy the full SHA
    53ff459 View commit details
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -1001,7 +1001,7 @@ public static IRubyObject each_with_objectCommon19(ThreadContext context, IRubyO
final Ruby runtime = context.runtime;
RubyEnumerable.callEach(runtime, context, self, Signature.OPTIONAL, new BlockCallback() {
public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
return block.call(ctx, new IRubyObject[]{runtime.newArray(packEnumValues(ctx, largs), arg)});
return block.call(ctx, packEnumValues(ctx, largs), arg);
}
});
return arg;
@@ -1016,7 +1016,7 @@ public static IRubyObject each_with_index19(ThreadContext context, IRubyObject s
return block.isGiven() ? each_with_indexCommon19(context, self, block, args) : enumeratorizeWithSize(context, self, "each_with_index", args, enumSizeFn(context, self));
}

@JRubyMethod
@JRubyMethod(required = 1)
public static IRubyObject each_with_object(ThreadContext context, IRubyObject self, IRubyObject arg, Block block) {
return block.isGiven() ? each_with_objectCommon19(context, self, block, arg) : enumeratorizeWithSize(context, self, "each_with_object", new IRubyObject[] { arg }, enumSizeFn(context, self));
}
9 changes: 3 additions & 6 deletions core/src/main/java/org/jruby/runtime/CallBlock.java
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
* rights and limitations under the License.
*
* Copyright (C) 2006 Ola Bini <ola@ologix.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -48,10 +48,7 @@ public static Block newCallClosure(IRubyObject self, RubyModule imClass, Signatu

@Deprecated
public static Block newCallClosure(IRubyObject self, RubyModule imClass, Arity arity, BlockCallback callback, ThreadContext context) {
Binding binding = context.currentBinding(self, Visibility.PUBLIC);
BlockBody body = new CallBlock(Signature.from(arity), callback, context);

return new Block(body, binding);
return newCallClosure(self, imClass, Signature.from(arity), callback, context);
}

private CallBlock(Signature signature, BlockCallback callback, ThreadContext context) {
@@ -91,7 +88,7 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyOb
Binding binding, Block.Type type) {
return callback.call(context, args, Block.NULL_BLOCK);
}

public StaticScope getStaticScope() {
return dummyScope;
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/runtime/Signature.java
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
* A representation of a Ruby method signature (argument layout, min/max, keyword layout, rest args).
*/
public class Signature {
public enum Rest { NONE, NORM, ANON, STAR }
public static enum Rest { NONE, NORM, ANON, STAR }

public static final Signature NO_ARGUMENTS = new Signature(0, 0, 0, Rest.NONE, 0, 0, false);
public static final Signature ONE_ARGUMENT = new Signature(1, 0, 0, Rest.NONE, 0, 0, false);
@@ -36,7 +36,7 @@ public enum Rest { NONE, NORM, ANON, STAR }
private final int kwargs;
private final int requiredKwargs;
private final Arity arity;
private boolean restKwargs;
private final boolean restKwargs;

public Signature(int pre, int opt, int post, Rest rest, int kwargs, int requiredKwargs, boolean restKwargs) {
this.pre = pre;
31 changes: 31 additions & 0 deletions spec/regression/GH-2943_each_with_object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe 'Enumerable#each_with_object' do

it 'reports argument error when no arguments given' do
begin
[].each_with_object
fail 'ArgumentError not raised!'
rescue ArgumentError => e
# TODO JRuby does seem to get a different error message than MRI
#expect( e.message ).to eql 'wrong number of arguments (0 for 1)'
end
end

it 'works with a 2 arg lambda passed as block' do
storategy = lambda { |str, hash| hash[str] = str }
result = %w(a b c d e f).each_with_object({}, &storategy)
expected = {"a"=>"a", "b"=>"b", "c"=>"c", "d"=>"d", "e"=>"e", "f"=>"f"}
expect( result ).to eql expected
end

it 'works just fine with a block' do
result = %w(a b c d e f).each_with_object({}) { |v, hash| hash[v] = v }
expected = {"a"=>"a", "b"=>"b", "c"=>"c", "d"=>"d", "e"=>"e", "f"=>"f"}
expect( result ).to eql expected

other = []
result = %w(a b c d e f).each_with_object({}) { |v| other << v }
expect( result ).to be_empty
expect( other ).to eql %w(a b c d e f)
end

end