Package org.jruby.runtime.builtin

Examples of org.jruby.runtime.builtin.IRubyObject.respondsTo()


    public static IRubyObject define_finalizer(IRubyObject recv, IRubyObject[] args, Block block) {
        Ruby runtime = recv.getRuntime();
        IRubyObject finalizer = null;
        if (args.length == 2) {
            finalizer = args[1];
            if (!finalizer.respondsTo("call")) {
                throw runtime.newArgumentError("wrong type argument "
                        + finalizer.getType() + " (should be callable)");
            }
        } else {
            finalizer = runtime.newProc(Block.Type.PROC, block);
View Full Code Here


                            break;
                        case ClassIndex.STRING:
                            arg = RubyNumeric.str2inum(arg.getRuntime(),(RubyString)arg,0,true);
                            break;
                        default:
                            if (arg.respondsTo("to_int")) {
                                arg = TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), MethodIndex.TO_INT, "to_int", true);
                            } else {
                                arg = TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), MethodIndex.TO_I, "to_i", true);
                            }
                            break;
View Full Code Here

                IRubyObject vKlassName = result.op_aref(context, parser.createId);
                if (!vKlassName.isNil()) {
                    // might throw ArgumentError, we let it propagate
                    IRubyObject klass = parser.info.jsonModule.get().
                            callMethod(context, "deep_const_get", vKlassName);
                    if (klass.respondsTo("json_creatable?") &&
                        klass.callMethod(context, "json_creatable?").isTrue()) {

                        returnedResult = klass.callMethod(context, "json_create", result);
                    }
                }
View Full Code Here

                if (!vKlassName.isNil()) {
                    // might throw ArgumentError, we let it propagate
                    IRubyObject klass = parser.info.jsonModule.get().
                            callMethod(context, "deep_const_get", vKlassName);
                    if (klass.respondsTo("json_creatable?") &&
                        klass.callMethod(context, "json_creatable?").isTrue()) {

                        returnedResult = klass.callMethod(context, "json_create", result);
                    }
                }
View Full Code Here

    public static IRubyObject define_finalizer(IRubyObject recv, IRubyObject[] args, Block block) {
        Ruby runtime = recv.getRuntime();
        IRubyObject finalizer = null;
        if (args.length == 2) {
            finalizer = args[1];
            if (!finalizer.respondsTo("call")) {
                throw runtime.newArgumentError("wrong type argument "
                        + finalizer.getType() + " (should be callable)");
            }
        } else {
            finalizer = runtime.newProc(Block.Type.PROC, block);
View Full Code Here

            if (range.include_p19(context, last).isTrue() && (!returnFloat)) {
                last = last.callMethod(context, "+", runtime.newFixnum(1));
            }

            if (!first.respondsTo("-") || !first.respondsTo("+") ||
                    !last.respondsTo("-") || !last.respondsTo("+")) {
                throw runtime.newArgumentError("invalid argument - " + arg.toString());
            }

            IRubyObject difference = last.callMethod(context, "-", first);
            if (returnFloat) {
View Full Code Here

            if (range.include_p19(context, last).isTrue() && (!returnFloat)) {
                last = last.callMethod(context, "+", runtime.newFixnum(1));
            }

            if (!first.respondsTo("-") || !first.respondsTo("+") ||
                    !last.respondsTo("-") || !last.respondsTo("+")) {
                throw runtime.newArgumentError("invalid argument - " + arg.toString());
            }

            IRubyObject difference = last.callMethod(context, "-", first);
            if (returnFloat) {
View Full Code Here

    }

    @JRubyMethod(name = "load", required = 1, optional = 1, module = true, visibility = PRIVATE, compat = RUBY1_9)
    public static IRubyObject load19(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
        IRubyObject file = args[0];
        if (!(file instanceof RubyString) && file.respondsTo("to_path")) {
            file = file.callMethod(context, "to_path");
        }

        return loadCommon(file, context.getRuntime(), args, block);
    }
View Full Code Here

        private static Class getAnnoClass(ThreadContext context, Object annoClass) {
            if (annoClass instanceof Class) {
                return (Class) annoClass;
            } else if (annoClass instanceof IRubyObject) {
                IRubyObject annoMod = (IRubyObject) annoClass;
                if (annoMod.respondsTo("java_class")) {
                    return (Class) annoMod.callMethod(context, "java_class").toJava(Object.class);
                }
            }
            throw context.getRuntime().newArgumentError("must supply java class argument instead of " + annoClass.toString());
        }
View Full Code Here

                            break;
                        case ClassIndex.STRING:
                            arg = ((RubyString)arg).stringToInum(0, true);
                            break;
                        default:
                            if (arg.respondsTo("to_int")) {
                                arg = TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), "to_int", true);
                            } else {
                                arg = TypeConverter.convertToType(arg, arg.getRuntime().getInteger(), "to_i", true);
                            }
                            break;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.