Package org.jruby

Examples of org.jruby.Ruby.newArray()


    public static IRubyObject gethostbyaddr(ThreadContext context, IRubyObject[] args) {
        Ruby runtime = context.runtime;
        IRubyObject[] ret = new IRubyObject[4];

        ret[0] = runtime.newString(Sockaddr.addressFromString(runtime, args[0].convertToString().toString()).getCanonicalHostName());
        ret[1] = runtime.newArray();
        ret[2] = runtime.newFixnum(2); // AF_INET
        ret[3] = args[0];

        return runtime.newArrayNoCopy(ret);
    }
View Full Code Here


        try {
            InetAddress addr = getRubyInetAddress(hostname.convertToString().getByteList());
            IRubyObject[] ret = new IRubyObject[4];

            ret[0] = runtime.newString(addr.getCanonicalHostName());
            ret[1] = runtime.newArray();
            ret[2] = runtime.newFixnum(2); // AF_INET
            ret[3] = runtime.newString(new ByteList(addr.getAddress()));
            return runtime.newArrayNoCopy(ret);

        } catch(UnknownHostException e) {
View Full Code Here

                    l.add(runtime.newArrayNoCopy(c));
                }
            }
        });

        return runtime.newArray(l);
    }

    public static List<Addrinfo> getaddrinfoList(ThreadContext context, IRubyObject[] args) {
        final Ruby runtime = context.runtime;
        final List<Addrinfo> l = new ArrayList<Addrinfo>();
View Full Code Here

            }

        }

        return runtime.newArray(runtime.newString(host), runtime.newString(port));

    }

    public static IRubyObject ip_address_list(ThreadContext context) {
        Ruby runtime = context.runtime;
View Full Code Here

    @JRubyMethod(name = "crc_table", module = true, visibility = PRIVATE)
    public static IRubyObject crc_table(IRubyObject recv) {
        Ruby runtime = recv.getRuntime();
        int[] table = com.jcraft.jzlib.CRC32.getCRC32Table();
        RubyArray array = runtime.newArray(table.length);
        for (int i = 0; i < table.length; i++) {
            array.append(runtime.newFixnum(table[i] & 0xffffffffL));
        }
        return array;
    }
View Full Code Here

                            runtime.newFixnum(port),
                            runtime.newString(hostName),
                            runtime.newString(hostAddress)
                    });

            return runtime.newArray(result, addressArray);

        } catch (BadDescriptorException e) {
            throw runtime.newErrnoEBADFError();
        }
    }
View Full Code Here

        int n = threadFdSelect(context);

        if (n == 0 && pendingReadFDs == null && n == 0 && unselectableReadFDs == null && unselectableWriteFDs == null) return context.nil; /* returns nil on timeout */

        res = RubyArray.newArray(runtime, 3);
        res.push(runtime.newArray(Math.min(n, maxReadReadySize())));
        res.push(runtime.newArray(Math.min(n, maxWriteReadySize())));
        // we never add anything for error since JDK does not provide a way to select for error
        res.push(runtime.newArray(0));

        if (readKeyList != null) {
View Full Code Here

        if (n == 0 && pendingReadFDs == null && n == 0 && unselectableReadFDs == null && unselectableWriteFDs == null) return context.nil; /* returns nil on timeout */

        res = RubyArray.newArray(runtime, 3);
        res.push(runtime.newArray(Math.min(n, maxReadReadySize())));
        res.push(runtime.newArray(Math.min(n, maxWriteReadySize())));
        // we never add anything for error since JDK does not provide a way to select for error
        res.push(runtime.newArray(0));

        if (readKeyList != null) {
            list = (RubyArray) res.eltOk(0);
View Full Code Here

        res = RubyArray.newArray(runtime, 3);
        res.push(runtime.newArray(Math.min(n, maxReadReadySize())));
        res.push(runtime.newArray(Math.min(n, maxWriteReadySize())));
        // we never add anything for error since JDK does not provide a way to select for error
        res.push(runtime.newArray(0));

        if (readKeyList != null) {
            list = (RubyArray) res.eltOk(0);
            for (i = 0; i < readAry.size(); i++) {
                IRubyObject obj = readAry.eltOk(i);
View Full Code Here

    public static IRubyObject impl(ThreadContext context, IRubyObject self, IRubyObject[] args, final Block implBlock) {
        Ruby runtime = context.runtime;

        if (!implBlock.isGiven()) throw runtime.newArgumentError("block required to call #impl on a Java interface");

        final RubyArray methodNames = (args.length > 0) ? runtime.newArray(args) : null;

        RubyClass implClass = RubyClass.newClass(runtime, runtime.getObject());
        implClass.include(new IRubyObject[] {self});

        IRubyObject implObject = implClass.callMethod(context, "new");
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.