@JRubyMethod(name = "method_missing", rest = true) public IRubyObject methodMissing(ThreadContext context, IRubyObject[] args) { if (args.length == 1) { RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass); IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]); if (oneofDescriptor.isNil()) { if (!hasField(args[0])) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return index(context, args[0]); } RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor; Descriptors.FieldDescriptor fieldDescriptor = oneofCases.get(rubyOneofDescriptor.getOneofDescriptor()); if (fieldDescriptor == null) return context.runtime.getNil(); return context.runtime.newSymbol(fieldDescriptor.getName()); } else { // fieldName is RubySymbol RubyString field = args[0].asString(); RubyString equalSign = context.runtime.newString(Utils.EQUAL_SIGN); if (field.end_with_p(context, equalSign).isTrue()) { field.chomp_bang(context, equalSign); } if (!hasField(field)) { return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK); } return indexSet(context, field, args[1]); } }
@JRubyMethod(name = "encode_json", meta = true) public static IRubyObject encodeJson(ThreadContext context, IRubyObject recv, IRubyObject msgRb) { RubyMessage message = (RubyMessage) msgRb; return Helpers.invoke(context, message.toHash(context), "to_json"); }
@JRubyMethod(frame = true, meta = true) public static IRubyObject inherited(ThreadContext context, IRubyObject recv, IRubyObject subclass) { IRubyObject subJavaClass = Helpers.invoke(context, subclass, "java_class"); if (subJavaClass.isNil()) { subJavaClass = Helpers.invoke(context, recv, "java_class"); Helpers.invoke(context, subclass, "java_class=", subJavaClass); } return Helpers.invokeSuper(context, recv, subclass, Block.NULL_BLOCK); }
@Override public Object retrieve(ThreadContext context, IRubyObject self, DynamicScope currDynScope, Object[] temp) { IRubyObject v1 = (IRubyObject)a1.retrieve(context, self, currDynScope, temp); IRubyObject v2 = (IRubyObject)a2.retrieve(context, self, currDynScope, temp); return isArgsPush ? Helpers.argsPush((RubyArray) v1, v2) : Helpers.argsCat(v1, v2); }
public static void addInstanceMethod(RubyModule containingClass, String name, DynamicMethod method, Visibility visibility, ThreadContext context, Ruby runtime) { containingClass.addMethod(name, method); RubySymbol sym = runtime.fastNewSymbol(name); if (visibility == Visibility.MODULE_FUNCTION) { addModuleMethod(containingClass, name, method, context, sym); } callNormalMethodHook(containingClass, context, sym); }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, IRubyObject arg0, Block block) { checkSuperDisabledOrOutOfMethod(context); RubyModule klazz = context.getFrameKlazz(); String name = context.getFrameName(); RubyClass selfClass = getMetaClass(self); RubyClass superClass = findImplementerIfNecessary(selfClass, klazz).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, selfClass, method.getVisibility(), name, CallType.SUPER, arg0, block); } return method.call(context, self, superClass, name, arg0, block); }
@JRubyMethod(frame = true) public IRubyObject min(ThreadContext context, Block block) { if (block.isGiven()) { return Helpers.invokeSuper(context, this, block); } int cmp = RubyComparable.cmpint(context, invokedynamic(context, begin, MethodNames.OP_CMP, end), begin, end); if (cmp > 0 || (cmp == 0 && isExclusive)) { return context.nil; } return begin; }
@JIT public static void defCompiledInstanceMethod(ThreadContext context, MethodHandle handle, IRScope method, DynamicScope currDynScope, IRubyObject self) { Ruby runtime = context.runtime; RubySymbol methodName = method.getName(); RubyModule clazz = findInstanceMethodContainer(context, currDynScope, self); Visibility currVisibility = context.getCurrentVisibility(); Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, clazz, methodName, currVisibility); DynamicMethod newMethod = new CompiledIRMethod(handle, method, newVisibility, clazz); // FIXME: needs checkID and proper encoding to force hard symbol Helpers.addInstanceMethod(clazz, methodName, newMethod, currVisibility, context, runtime); }
public static IRubyObject[] arraySlice1N(IRubyObject arrayish) { arrayish = aryToAry(arrayish); RubyArray arrayish2 = ensureMultipleAssignableRubyArray(arrayish, arrayish.getRuntime(), true); return new IRubyObject[] {arrayEntryOrNilZero(arrayish2), subarrayOrEmpty(arrayish2, arrayish2.getRuntime(), 1)}; }
/** * Arity one method_missing invocation */ public static IRubyObject callMethodMissing(CacheEntry entry, CallType callType, ThreadContext context, IRubyObject self, RubyClass selfClass, String name, IRubyObject arg0, Block block) { return Helpers.callMethodMissing(context, self, selfClass, entry.method.getVisibility(), name, callType, arg0, block); }
public static RubyArray arrayValue(IRubyObject value) { Ruby runtime = value.getRuntime(); return arrayValue(runtime.getCurrentContext(), runtime, value); }
static IRubyObject[] restructureBlockArgs(ThreadContext context, IRubyObject value, Signature signature, Block.Type type, boolean needsSplat) { if (!type.checkArity && signature == Signature.NO_ARGUMENTS) return IRubyObject.NULL_ARRAY; if (value == null) return IRubyObject.NULL_ARRAY; if (needsSplat) { IRubyObject ary = Helpers.aryToAry(context, value); if (ary instanceof RubyArray) return ((RubyArray) ary).toJavaArrayMaybeUnsafe(); } return new IRubyObject[] { value }; }
public StringLiteral(ByteList val) { bytelist = val; string = Helpers.byteListToString(bytelist); }
public static IRubyObject arraySlice1(IRubyObject arrayish) { arrayish = aryToAry(arrayish); RubyArray arrayish2 = ensureMultipleAssignableRubyArray(arrayish, arrayish.getRuntime(), true); return arrayEntryOrNilZero(arrayish2); }
public static IRubyObject def(ThreadContext context, IRubyObject self, Object scriptObject, String rubyName, String javaName, StaticScope scope, int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc) { Class compiledClass = scriptObject.getClass(); Ruby runtime = context.runtime; RubyModule containingClass = context.getRubyClass(); Visibility visibility = context.getCurrentVisibility(); performNormalMethodChecks(containingClass, runtime, rubyName); MethodFactory factory = MethodFactory.createFactory(compiledClass.getClassLoader()); DynamicMethod method = constructNormalMethod( factory, javaName, rubyName, containingClass, new SimpleSourcePosition(filename, line), arity, scope, visibility, scriptObject, callConfig, parameterDesc); addInstanceMethod(containingClass, rubyName, method, visibility,context, runtime); return runtime.getNil(); }
@Deprecated public static RubySymbol addInstanceMethod(RubyModule containingClass, String name, DynamicMethod method, Visibility visibility, ThreadContext context, Ruby runtime) { return addInstanceMethod(containingClass, runtime.fastNewSymbol(name), method, visibility, context, runtime); }
@Deprecated public static RubyArray argsCat(IRubyObject first, IRubyObject second) { return argsCat(first.getRuntime().getCurrentContext(), first, second); }
@JRubyMethod(frame = true, meta = true) public static IRubyObject inherited(ThreadContext context, IRubyObject recv, IRubyObject subclass) { IRubyObject subJavaClass = Helpers.invoke(context, subclass, "java_class"); if (subJavaClass.isNil()) { subJavaClass = Helpers.invoke(context, recv, "java_class"); Helpers.invoke(context, subclass, "java_class=", subJavaClass); } return Helpers.invokeSuper(context, recv, subclass, Block.NULL_BLOCK); }
@Override public Object retrieve(ThreadContext context, IRubyObject self, DynamicScope currDynScope, Object[] temp) { IRubyObject v1 = (IRubyObject)a1.retrieve(context, self, currDynScope, temp); IRubyObject v2 = (IRubyObject)a2.retrieve(context, self, currDynScope, temp); return isArgsPush ? Helpers.argsPush((RubyArray) v1, v2) : Helpers.argsCat(v1, v2); }
public static void addInstanceMethod(RubyModule containingClass, String name, DynamicMethod method, Visibility visibility, ThreadContext context, Ruby runtime) { containingClass.addMethod(name, method); RubySymbol sym = runtime.fastNewSymbol(name); if (visibility == Visibility.MODULE_FUNCTION) { addModuleMethod(containingClass, name, method, context, sym); } callNormalMethodHook(containingClass, context, sym); }