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


        if (arg2 instanceof RubyString) {
            io2 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[] {arg2, runtime.newString("w")}, Block.NULL_BLOCK);
        } else if (arg2 instanceof RubyIO) {
            io2 = (RubyIO) arg2;
        } else if (arg2.respondsTo("to_path")) {
            RubyString path = (RubyString) TypeConverter.convertToType19(arg2, runtime.getString(), "to_path");
            io2 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[] {path, runtime.newString("w")}, Block.NULL_BLOCK);
        } else if (arg2.respondsTo("write")) {
            if (read == null) {
                if (length == null) {
View Full Code Here

        } else if (arg2 instanceof RubyIO) {
            io2 = (RubyIO) arg2;
        } else if (arg2.respondsTo("to_path")) {
            RubyString path = (RubyString) TypeConverter.convertToType19(arg2, runtime.getString(), "to_path");
            io2 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[] {path, runtime.newString("w")}, Block.NULL_BLOCK);
        } else if (arg2.respondsTo("write")) {
            if (read == null) {
                if (length == null) {
                    read = io1.read(context, runtime.getNil()).convertToString();
                } else {
                    read = io1.read(context, length).convertToString();
View Full Code Here

    }
   
    public static IRubyObject convert2ptr(ThreadContext context, IRubyObject parameter) {
        final int MAXRECURSE = 4;
        IRubyObject ptr = parameter;
        for (int i = 0; i < MAXRECURSE && !(ptr instanceof AbstractMemory) && ptr.respondsTo("to_ptr"); i++) {
            ptr = ptr.callMethod(context, "to_ptr");
        }

        return ptr;
    }
View Full Code Here

    private static MemoryIO convertToPointerMemoryIO(IRubyObject parameter) {
        IRubyObject obj = parameter;
        ThreadContext context = parameter.getRuntime().getCurrentContext();
        for (int depth = 0; depth < 4; depth++) {
            if (obj.respondsTo("to_ptr")) {
                obj = obj.callMethod(context, "to_ptr");
                MemoryIO memory = lookupPointerMemoryIO(obj);
                if (memory != null) {
                    return memory;
                }
View Full Code Here

            } catch (RaiseException typeError) {
            }
        }

        String zone = "";
        if (zoneVar != null && zoneVar.respondsTo("to_str")) {
            try {
                zone = zoneVar.convertToString().toString();
            } catch (RaiseException typeError) {
            }
        }
View Full Code Here

                            break;
                        case 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

        setConnection( connection = newConnection() );
        final IRubyObject adapter = getAdapter(); // self.adapter
        if ( adapter == null || adapter.isNil() ) {
            warn(context, "adapter not set, please pass adapter on JdbcConnection#initialize(config, adapter)");
        }
        else if ( adapter.respondsTo("init_connection") ) {
            return adapter.callMethod(context, "init_connection", convertJavaToRuby(connection));
        }
        return context.nil;
    }
View Full Code Here

            setConnection( newConnection() );
            final IRubyObject adapter = getAdapter(); // self.adapter
            //if ( adapter.isNil() ) {
                // NOTE: we warn on init_connection - should be enough
            //}
            if ( adapter.respondsTo("configure_connection") ) {
                adapter.callMethod(context, "configure_connection");
            }
            return context.nil;
        }
        catch (SQLException e) {
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.