Skip to content

Commit fda9948

Browse files
committed
Splats: Call method_missing if defined when to_ary/to_a are missing
* This should fix #2410, but requires code review and possibly some tests.
1 parent 4948b9b commit fda9948

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/src/main/java/org/jruby/runtime/Helpers.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,20 @@ public static RubyArray arrayValue(ThreadContext context, Ruby runtime, IRubyObj
18591859
}
18601860
return (RubyArray)avalue;
18611861
} else {
1862-
return runtime.newArray(value);
1862+
DynamicMethod methodMissing = value.getMetaClass().searchMethod("method_missing");
1863+
if (methodMissing.isUndefined() || methodMissing.equals(runtime.getDefaultMethodMissing())) {
1864+
return runtime.newArray(value);
1865+
} else {
1866+
IRubyObject avalue = methodMissing.call(context, value, value.getMetaClass(), "to_a", new IRubyObject[] {runtime.newSymbol("to_a")}, Block.NULL_BLOCK);
1867+
if (!(avalue instanceof RubyArray)) {
1868+
if (avalue.isNil()) {
1869+
return runtime.newArray(value);
1870+
} else {
1871+
throw runtime.newTypeError("`to_a' did not return Array");
1872+
}
1873+
}
1874+
return (RubyArray)avalue;
1875+
}
18631876
}
18641877
}
18651878
RubyArray arr = (RubyArray) tmp;

0 commit comments

Comments
 (0)