Package org.jruby

Examples of org.jruby.RubyArray$RubyArrayConversionIterator


            // rest arg must be splatted
            IRubyObject restArg = getValue(staticScope.getRestArg(), 0);
            assert restArg != null;
           
            // FIXME: not very efficient
            RubyArray splattedArgs = RuntimeHelpers.splatValue(restArg);           
            IRubyObject[] argValues = new IRubyObject[totalArgs + splattedArgs.size()];
            System.arraycopy(splattedArgs.toJavaArray(), 0, argValues, totalArgs, splattedArgs.size());
            switch (totalArgs) {
            case 3:
                argValues[2] = variableValueTwo;
            case 2:
                argValues[1] = variableValueOne;
View Full Code Here


        RubyException exception = (RubyException)runtime.getClass("NameError").newInstance(ruby.getCurrentContext(), new IRubyObject[]{ruby.newString("A message")},  Block.NULL_BLOCK);
        RubyString[] lines = new RubyString[]{
            RubyString.newString(ruby, "Line 1"),
            RubyString.newString(ruby, "Line 2"),
        };
        RubyArray backtrace = RubyArray.newArray(ruby, Arrays.asList(lines));
        exception.set_backtrace(backtrace);
        ruby.printError(exception);
        assertEquals("Line 1: A message (NameError)\n\tfrom Line 2\n", err.toString());
    }
View Full Code Here

                    script.append("require '" + scriptName() + "'\n");
                    script.append("runner = Test::Unit::UI::JUnit::TestRunner.new(" + testClass + ")\n");
                    script.append("runner.start\n");
                    script.append("runner.faults\n");
   
                    RubyArray faults = (RubyArray)runtime.executeScript(script.toString(), scriptName() + "_generated_test.rb");
   
                    if (!faults.isEmpty()) {
                        StringBuffer faultString = new StringBuffer("Faults encountered running " + scriptName() + ", complete output follows:\n");
                        for (Iterator iter = faults.iterator(); iter.hasNext();) {
                            String fault = iter.next().toString();
   
                            faultString.append(fault).append("\n");
                        }
   
View Full Code Here

            script.append("require 'test/minirunit'").append('\n');
            script.append("$silentTests = true").append('\n');
            script.append("test_load('").append(scriptName()).append("')").append('\n');
            script.append("$failed").append('\n');

            RubyArray lastFailed = (RubyArray)runtime.executeScript(script.toString(), scriptName() + "_generated_test.rb");
           
            if (!lastFailed.isEmpty()) {
                RubyString message = (RubyString) lastFailed.callMethod(lastFailed.getRuntime().getCurrentContext(), "to_s");
                fail(scriptName() + " failed, complete failure list follows:\n" + message.toString());
            }

            System.out.flush(); // Without a flush Ant will miss some of our output
        }
View Full Code Here

            // rest arg must be splatted
            IRubyObject restArg = getValue(staticScope.getRestArg(), 0);
            assert restArg != null;
           
            // FIXME: not very efficient
            RubyArray splattedArgs = RuntimeHelpers.splatValue(restArg);           
            IRubyObject[] argValues = new IRubyObject[totalArgs + splattedArgs.size()];
            System.arraycopy(variableValues, 0, argValues, 0, totalArgs);
            System.arraycopy(splattedArgs.toJavaArray(), 0, argValues, totalArgs, splattedArgs.size());
           
            return argValues;
        }
    }
View Full Code Here

            // rest arg must be splatted
            IRubyObject restArg = getValue(staticScope.getRestArg(), 0);
            assert restArg != null;
           
            // FIXME: not very efficient
            RubyArray splattedArgs = RuntimeHelpers.splatValue(restArg);           
            IRubyObject[] argValues = new IRubyObject[totalArgs + splattedArgs.size()];
            System.arraycopy(splattedArgs.toJavaArray(), 0, argValues, totalArgs, splattedArgs.size());
           
            if (totalArgs == 1) {
                argValues[0] = variableValueZero;
            }
           
View Full Code Here

                    .jsonModule.get().callMethod(context, "create_id");
            result.op_aset(context, createId, self.getMetaClass().to_s());

            ByteList bl = self.getByteList();
            byte[] uBytes = bl.unsafeBytes();
            RubyArray array = runtime.newArray(bl.length());
            for (int i = bl.begin(), t = bl.begin() + bl.length(); i < t; i++) {
                array.store(i, runtime.newFixnum(uBytes[i] & 0xff));
            }

            result.op_aset(context, runtime.newString("raw"), array);
            return result;
        }
View Full Code Here

            IRubyObject rawData = o.fastARef(runtime.newString("raw"));
            if (rawData == null) {
                throw runtime.newArgumentError("\"raw\" value not defined "
                                               + "for encoded String");
            }
            RubyArray ary = Utils.ensureArray(rawData);
            byte[] bytes = new byte[ary.getLength()];
            for (int i = 0, t = ary.getLength(); i < t; i++) {
                IRubyObject element = ary.eltInternal(i);
                if (element instanceof RubyFixnum) {
                    bytes[i] = (byte)RubyNumeric.fix2long(element);
                } else {
                    throw runtime.newTypeError(element, runtime.getFixnum());
                }
View Full Code Here

    }

    @Override
    public void assignArray(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject arg,
            Block block) {
        RubyArray values = (RubyArray) arg;
        int length = values.getLength();

        switch (length) {
            case 0:
                assign(runtime, context, self, block);
                break;
            case 1:
                assign(runtime, context, self, values.eltInternal(0), block);
                break;
            case 2:
                assign(runtime, context, self, values.eltInternal(0), values.eltInternal(1), block);
                break;
            case 3:
                assign(runtime, context, self, values.eltInternal(0), values.eltInternal(1),
                        values.eltInternal(2), block);
                break;
            default:
                parameter1.assign(runtime, context, self, values.eltInternal(0), block, false);
                parameter2.assign(runtime, context, self, values.eltInternal(1), block, false);
                parameter3.assign(runtime, context, self, values.eltInternal(2), block, false);

                rest.assign(runtime, context, self, values.subseqLight(3, length - 3), block, true);
                break;
        }
    }
View Full Code Here

    }

    @Override
    public void assignArray(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject arg,
            Block block) {
        RubyArray values = (RubyArray) arg;
        int valueLength = values.getLength();

        switch (valueLength) {
            case 0:
                assign(runtime, context, self, block);
                break;
            case 1:
                assign(runtime, context, self, values.eltInternal(0), block);
                break;
            case 2:
                assign(runtime, context, self, values.eltInternal(0), values.eltInternal(1), block);
                break;
            case 3:
                assign(runtime, context, self, values.eltInternal(0), values.eltInternal(1),
                        values.eltInternal(2), block);
                break;
        }

        // Populate up to shorter of calling arguments or local parameters in the block
        for (int i = 0; i < preLength && i < valueLength; i++) {
            pre.get(i).assign(runtime, context, self, values.eltInternal(i), block, false);
        }
    }
View Full Code Here

TOP

Related Classes of org.jruby.RubyArray$RubyArrayConversionIterator

Copyright © 2018 www.massapicom. 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.