Skip to content

Commit

Permalink
let us fix __send__ routing of native methods when it has overloads
Browse files Browse the repository at this point in the history
suppose a method is implemented in block-less form in native code e.g.
```
static civil(ThreadContext context, IRubyObject self)
static civil(ThreadContext context, IRubyObject self, IRubyObject[] args)
```

doing a `Date.civil` will properly route to `civil(context, self)`
while a `Date.send(:civil)` ends up being routed through args case
kares committed Feb 28, 2018
1 parent 863f012 commit 3b821f7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -1719,19 +1719,25 @@ public static IRubyObject method_missing19(ThreadContext context, IRubyObject re
@JRubyMethod(name = "__send__", omit = true)
public IRubyObject send(ThreadContext context, IRubyObject arg0, Block block) {
String name = RubySymbol.objectToSymbolString(arg0);

if (block == Block.NULL_BLOCK) {
return getMetaClass().finvoke(context, this, name);
}
return getMetaClass().finvoke(context, this, name, block);
}
@JRubyMethod(name = "__send__", omit = true)
public IRubyObject send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
String name = RubySymbol.objectToSymbolString(arg0);

if (block == Block.NULL_BLOCK) {
return getMetaClass().finvoke(context, this, name, arg1);
}
return getMetaClass().finvoke(context, this, name, arg1, block);
}
@JRubyMethod(name = "__send__", omit = true)
public IRubyObject send(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
String name = RubySymbol.objectToSymbolString(arg0);

if (block == Block.NULL_BLOCK) {
return getMetaClass().finvoke(context, this, name, arg1, arg2);
}
return getMetaClass().finvoke(context, this, name, arg1, arg2, block);
}
@JRubyMethod(name = "__send__", required = 1, rest = true, omit = true)
@@ -1740,6 +1746,9 @@ public IRubyObject send(ThreadContext context, IRubyObject[] args, Block block)

final int length = args.length - 1;
args = ( length == 0 ) ? IRubyObject.NULL_ARRAY : ArraySupport.newCopy(args, 1, length);
if (block == Block.NULL_BLOCK) {
return getMetaClass().finvoke(context, this, name, args);
}
return getMetaClass().finvoke(context, this, name, args, block);
}

0 comments on commit 3b821f7

Please sign in to comment.