public class InvokeDynamicSupport {
public static Object bootstrap(final CallSite site, Object... args) {
// dynamic call
IRubyObject self = (IRubyObject) args[0];
ThreadContext context = (ThreadContext) args[1];
String methodName = (String) args[2];
CallType callType = CallType.NORMAL;
String siteName = site.name();
boolean iterator = siteName.length() == 2 && siteName.charAt(1) == 'b';
switch (siteName.charAt(0)) {
case 'c':
callType = CallType.NORMAL;
break;
case 'f':
callType = CallType.FUNCTIONAL;
break;
case 'v':
callType = CallType.VARIABLE;
break;
}
DynamicMethod method = self.getMetaClass().searchMethod(methodName);
IRubyObject caller = context.getFrameSelf();
if (shouldCallMethodMissing(method, methodName, caller, callType)) {
return RuntimeHelpers.callMethodMissing(context, self, method, methodName, callType, Block.NULL_BLOCK);
}
String dispatcherName = iterator ? "invokeDynamicIter" : "invokeDynamic";