Skip to content
Permalink
Browse files
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.
  • Loading branch information
subbuss committed Jan 7, 2015
1 parent 4948b9b commit fda9948
Showing 1 changed file with 14 additions and 1 deletion.
@@ -1859,7 +1859,20 @@ public static RubyArray arrayValue(ThreadContext context, Ruby runtime, IRubyObj
}
return (RubyArray)avalue;
} else {
return runtime.newArray(value);
DynamicMethod methodMissing = value.getMetaClass().searchMethod("method_missing");
if (methodMissing.isUndefined() || methodMissing.equals(runtime.getDefaultMethodMissing())) {
return runtime.newArray(value);
} else {
IRubyObject avalue = methodMissing.call(context, value, value.getMetaClass(), "to_a", new IRubyObject[] {runtime.newSymbol("to_a")}, Block.NULL_BLOCK);
if (!(avalue instanceof RubyArray)) {
if (avalue.isNil()) {
return runtime.newArray(value);
} else {
throw runtime.newTypeError("`to_a' did not return Array");
}
}
return (RubyArray)avalue;
}
}
}
RubyArray arr = (RubyArray) tmp;

0 comments on commit fda9948

Please sign in to comment.