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: 5a87b024329b
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0ca1046655a0
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on May 14, 2015

  1. Attempt towards fixing/simplifying block yield parm binding. Separate…

    … lambda/non-lambda doYield
    enebo committed May 14, 2015
    Copy the full SHA
    31cab2e View commit details
  2. Copy the full SHA
    49bf2c1 View commit details
  3. Tag out now passing tests and fix Method#original_name to return name…

    … as symbol instead of string
    enebo committed May 14, 2015
    Copy the full SHA
    0ca1046 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
@@ -308,7 +308,7 @@ public IRubyObject super_method(ThreadContext context) {
@JRubyMethod
public IRubyObject original_name(ThreadContext context) {
if (method instanceof AliasMethod) {
return context.runtime.newString(((AliasMethod)method).getOldName());
return context.runtime.newSymbol(((AliasMethod)method).getOldName());
}
return name(context);
}
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1774,7 +1774,6 @@ public IRubyObject define_method(ThreadContext context, IRubyObject arg0, Block
@JRubyMethod(name = "define_method", visibility = PRIVATE, reads = VISIBILITY)
public IRubyObject define_method(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
Ruby runtime = context.runtime;
IRubyObject body;
String name = TypeConverter.convertToIdentifier(arg0);
DynamicMethod newMethod = null;
Visibility visibility = PUBLIC;
@@ -1788,17 +1787,14 @@ public IRubyObject define_method(ThreadContext context, IRubyObject arg0, IRubyO
if (runtime.getProc().isInstance(arg1)) {
// double-testing args.length here, but it avoids duplicating the proc-setup code in two places
RubyProc proc = (RubyProc)arg1;
body = proc;

newMethod = createProcMethod(name, visibility, proc);
} else if (arg1 instanceof AbstractRubyMethod) {
AbstractRubyMethod method = (AbstractRubyMethod)arg1;
body = method;

checkValidBindTargetFrom(context, (RubyModule)method.owner(context));

newMethod = method.getMethod().dup();
newMethod.setImplementationClass(this);
newMethod = new WrapperMethod(this, method.getMethod(), visibility);
} else {
throw runtime.newTypeError("wrong argument type " + arg1.getType().getName() + " (expected Proc/Method)");
}
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
package org.jruby.internal.runtime.methods;

import org.jruby.RubyModule;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
@@ -101,4 +102,9 @@ public long getSerialNumber() {
public DynamicMethod getRealMethod() {
return method;
}

@Override
public Arity getArity() {
return method.getArity();
}
}
34 changes: 23 additions & 11 deletions core/src/main/java/org/jruby/runtime/IRBlockBody.java
Original file line number Diff line number Diff line change
@@ -102,26 +102,38 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyO
return yieldSpecificMultiArgsCommon(context, new IRubyObject[] { arg0, arg1, arg2 }, binding, type);
}

private IRubyObject[] toAry(ThreadContext context, IRubyObject value) {
IRubyObject val0 = Helpers.aryToAry(value);

if (!(val0 instanceof RubyArray)) {
throw context.runtime.newTypeError(value.getType().getName() + "#to_ary should return Array");
}

return ((RubyArray)val0).toJavaArray();
}

protected IRubyObject doYieldLambda(ThreadContext context, IRubyObject value, Binding binding, Type type) {
// Lambda does not splat arrays even if a rest arg is present when it wants a single parameter filled.
IRubyObject[] args = signature.required() == 1 ? new IRubyObject[] { value } : toAry(context, value);

signature.checkArity(context.runtime, args);

return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
}

@Override
public IRubyObject doYield(ThreadContext context, IRubyObject value, Binding binding, Type type) {
IRubyObject[] args;
if (type == Type.LAMBDA) return doYieldLambda(context, value, binding, type);

int blockArity = getSignature().arityValue();

// For lambdas, independent of whether there is a REST arg or not, if # required args is 1,
// the value is passed through unmodified even when it is an array!
if ((type == Type.LAMBDA && signature.required() == 1) || (blockArity >= -1 && blockArity <= 1)) {
IRubyObject[] args;
if (blockArity >= -1 && blockArity <= 1) {
args = new IRubyObject[] { value };
} else {
IRubyObject val0 = Helpers.aryToAry(value);
if (!(val0 instanceof RubyArray)) {
throw context.runtime.newTypeError(value.getType().getName() + "#to_ary should return Array");
}
args = ((RubyArray)val0).toJavaArray();
args = toAry(context, value);
}

if (type == Type.LAMBDA) signature.checkArity(context.runtime, args);

return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
}

1 change: 0 additions & 1 deletion spec/tags/ruby/core/method/eql_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/ruby/core/method/equal_value_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions test/mri/excludes/TestMethod.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
exclude :test___dir__, "needs investigation"
exclude :test_alias_owner, "needs investigation"
exclude :test_arity, "needs investigation"
exclude :test_body, "needs investigation"
exclude :test_callee, "needs investigation"
exclude :test_clone, "needs investigation"
@@ -9,8 +8,6 @@
exclude :test_eq, "needs investigation"
exclude :test_hash, "needs investigation"
exclude :test_inspect, "needs investigation"
exclude :test_public_methods_with_extended, "needs investigation"
exclude :test_receiver_name_owner, "needs investigation"
exclude :test_singleton_method, "needs investigation"
exclude :test_super_in_proc_from_define_method, "needs investigation"
exclude :test_super_method_removed, "finds super method when super method has been undef (#2155)"