Examples of RubyArray


Examples of org.jruby.RubyArray

    public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        IRubyObject receiver = getReceiverNode().interpret(runtime, context, self, aBlock);
        IRubyObject arg = getArgsNode().interpret(runtime, context, self, aBlock);
       
        if (arg instanceof RubyArray) {
            RubyArray nodes = (RubyArray) arg;
           
            switch (nodes.size()) {
                case 0:
                    return callAdapter.call(context, self, receiver);
                case 1:
                    return callAdapter.call(context, self, receiver, nodes.eltInternal(0));
                case 2:
                    return callAdapter.call(context, self, receiver, nodes.eltInternal(0), nodes.eltInternal(1));
                case 3:
                    return callAdapter.call(context, self, receiver, nodes.eltInternal(0), nodes.eltInternal(1), nodes.eltInternal(2));
                default:
                    return callAdapter.call(context, self, receiver, nodes.toJavaArrayMaybeUnsafe());
            }
        }
       
        return callAdapter.call(context, self, receiver, arg);
    }
View Full Code Here

Examples of org.jruby.RubyArray

                    if (!(var instanceof RubyArray)) {
                        throw runtime.newTypeError(
                                "invalid java_interfaces defined for proxy (or ancestor): " +
                                ancestor + ": " + var);
                    }
                    RubyArray ifcArray = (RubyArray)var;
                    int size = ifcArray.size();
                    for (int i = size; --i >= 0; ) {
                        IRubyObject ifc = ifcArray.eltInternal(i);
                        if (!(ifc instanceof JavaClass)) {
                            throw runtime.newTypeError(
                                "invalid java interface defined for proxy (or ancestor): " +
                                ancestor + ": " + ifc);
                        }
                        Class interfaceClass = ((JavaClass)ifc).javaClass();
                        if (!interfaceClass.isInterface()) {
                            throw runtime.newTypeError(
                                    "invalid java interface defined for proxy (or ancestor): " +
                                    ancestor + ": " + ifc + " (not an interface)");
                        }
                        if (!interfaceList.contains(interfaceClass)) {
                            interfaceList.add(interfaceClass);
                        }
                    }
                }
                // set this class's method names in var @__java_ovrd_methods if this
                // is the new class; otherwise, get method names from there if this is
                // a proxy superclass.
               
                // FIXME: shouldn't need @__java_ovrd_methods, just query locally defined methods.
               
                var = ancestor.getInstanceVariables().fastGetInstanceVariable("@__java_ovrd_methods");
                if (var == null) {
                    // lock in the overridden methods for the new class, and any as-yet
                    // uninstantiated ancestor class.
                    Map<String, DynamicMethod> methods;
                    RubyArray methodNames;
                    synchronized(methods = ancestor.getMethods()) {
                        methodNames = RubyArray.newArrayLight(runtime,methods.size());
                        for (String methodName: methods.keySet()) {
                            if (!EXCLUDE_METHODS.contains(methodName)) {
                                names.add(methodName);
                                methodNames.append(runtime.newString(methodName));
                            }
                        }
                    }
                    ancestor.fastSetInstanceVariable("@__java_ovrd_methods",methodNames);
                } else {
                    if (!(var instanceof RubyArray)) {
                        throw runtime.newTypeError(
                                "invalid @__java_ovrd_methods defined for proxy: " +
                                ancestor + ": " + var);
                    }
                    RubyArray methodNames = (RubyArray)var;
                    int size = methodNames.size();
                    for (int i = size; --i >= 0; ) {
                        IRubyObject methodName = methodNames.eltInternal(i);
                        if (!(methodName instanceof RubyString)) {
                            throw runtime.newTypeError(
                                    "invalid method name defined for proxy (or ancestor): " +
                                    ancestor + ": " + methodName);
                        }
View Full Code Here

Examples of org.jruby.RubyArray

        if (rawArgs.length == 1) {
            synchronized (runtime.getLoadService()) {
                runtime.getLoadService().require("jruby/path_helper");
            }
            RubyModule pathHelper = runtime.getClassFromPath("JRuby::PathHelper");
            RubyArray parts = (RubyArray) RuntimeHelpers.invoke(context, pathHelper, "smart_split_command", rawArgs);
            args = new String[parts.getLength()];
            for (int i = 0; i < parts.getLength(); i++) {
                args[i] = parts.entry(i).toString();
            }
        } else {
            args = new String[rawArgs.length];
            for (int i = 0; i < rawArgs.length; i++) {
                args[i] = rawArgs[i].toString();
View Full Code Here

Examples of org.jruby.RubyArray

    public IRubyObject interpret(Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
        IRubyObject arg = getArgsNode().interpret(runtime, context, self, aBlock);
        Block block = getBlock(runtime, context, self, aBlock);
       
        if (arg instanceof RubyArray) {
            RubyArray nodes = (RubyArray) arg;
           
            switch (nodes.size()) {
                case 0:
                    return callAdapter.call(context, self, self, block);
                case 1:
                    return callAdapter.call(context, self, self, nodes.eltInternal(0), block);
                case 2:
                    return callAdapter.call(context, self, self, nodes.eltInternal(0), nodes.eltInternal(1), block);
                case 3:
                    return callAdapter.call(context, self, self, nodes.eltInternal(0), nodes.eltInternal(1), nodes.eltInternal(2), block);
                default:
                    return callAdapter.call(context, self, self, nodes.toJavaArrayMaybeUnsafe(), block);
            }
        }
       
        return callAdapter.call(context, self, self, arg, block);
    }
View Full Code Here

Examples of org.jruby.RubyArray

        IRubyObject receiver = receiverNode.interpret(runtime, context, self, block);
       
        if (argsNode == null) { // attribute set.
            RuntimeHelpers.invoke(context, receiver, name, value);
        } else { // element set
            RubyArray args = (RubyArray) argsNode.interpret(runtime, context, self, block);
            args.append(value);
            RuntimeHelpers.invoke(context, receiver, name, args.toJavaArray());
        }
       
        return runtime.getNil();
    }
View Full Code Here

Examples of org.jruby.RubyArray

        IRubyObject receiver = receiverNode.interpret(runtime, context, self, block);

        if (argsNode == null) { // attribute set.
            RuntimeHelpers.invoke(context, receiver, name, value, CallType.NORMAL, Block.NULL_BLOCK);
        } else { // element set
            RubyArray args = (RubyArray) argsNode.interpret(runtime, context, self, block);
            args.append(value);
            RuntimeHelpers.invoke(context, receiver, name, args.toJavaArray(), CallType.NORMAL, Block.NULL_BLOCK);
        }
       
        return runtime.getNil();
    }
View Full Code Here

Examples of org.jruby.RubyArray

    public static RubyArray createSubarray(IRubyObject[] input, Ruby runtime, int start) {
        return RubyArray.newArrayNoCopy(runtime, input, start);
    }
   
    public static RubyBoolean isWhenTriggered(IRubyObject expression, IRubyObject expressionsObject, ThreadContext context) {
        RubyArray expressions = RuntimeHelpers.splatValue(expressionsObject);
        for (int j = 0,k = expressions.getLength(); j < k; j++) {
            IRubyObject condition = expressions.eltInternal(j);

            if ((expression != null && condition.callMethod(context, MethodIndex.OP_EQQ, "===", expression)
                    .isTrue())
                    || (expression == null && condition.isTrue())) {
                return context.getRuntime().getTrue();
View Full Code Here

Examples of org.jruby.RubyArray

    public static IRubyObject aValueSplat(IRubyObject value) {
        if (!(value instanceof RubyArray) || ((RubyArray) value).length().getLongValue() == 0) {
            return value.getRuntime().getNil();
        }

        RubyArray array = (RubyArray) value;

        return array.getLength() == 1 ? array.first() : array;
    }
View Full Code Here

Examples of org.jruby.RubyArray

    public RubyArray declared_instance_methods() {
        return java_methods(javaClass().getDeclaredMethods(), false);
    }

    private RubyArray java_methods(Method[] methods, boolean isStatic) {
        RubyArray result = getRuntime().newArray(methods.length);
        for (int i = 0; i < methods.length; i++) {
            Method method = methods[i];
            if (isStatic == Modifier.isStatic(method.getModifiers())) {
                result.append(JavaMethod.create(getRuntime(), method));
            }
        }
        return result;
    }
View Full Code Here

Examples of org.jruby.RubyArray

        return argumentTypes;
    }

    @JRubyMethod
    public RubyArray constructors() {
        RubyArray ctors;
        if ((ctors = constructors) != null) return ctors;
        return constructors = buildConstructors(javaClass().getConstructors());
    }
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.