Examples of toJava()


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

        instance.put("@t", 2);
        result = instance.parse(reader, filename);
        IRubyObject ret = result.run();
        String expStringResult =
            "Trick or Treat!\nTrick or Treat!\n\nHmmm...I'd like trick.";
        assertEquals(expStringResult, ret.toJava(String.class));

        // line number test
        filename = basedir + "/core/src/test/ruby/org/jruby/embed/ruby/raises_parse_error.rb";
        reader = new FileReader(filename);
        StringWriter sw = new StringWriter();
View Full Code Here

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

        }

        filename = basedir + "/core/src/test/ruby/org/jruby/embed/ruby/next_year.rb";
        result = instance.parse(PathType.ABSOLUTE, filename);
        IRubyObject ret = result.run();
        assertEquals(getNextYear(), ret.toJava(Integer.class));

        StringWriter sw = new StringWriter();
        instance.setWriter(sw);
        String[] planets = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"};
        instance.put("@list", Arrays.asList(planets));
View Full Code Here

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

        result = instance.parse(istream, filename);
        instance.put("@a", 1);
        instance.put("@b", 1);
        instance.put("@c", 1);
        IRubyObject ret = result.run();
        List<Double> angles = (List) ret.toJava(List.class);
        // this result goes to 60.00000000000001,60.00000000000001,59.99999999999999.
        // these should be 60.0, 60.0, 60.0. conversion precision error?
        for (double angle : angles) {
            assertEquals(60.0, angle, 0.00001);
        }
View Full Code Here

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

            "return volume, surface_area";
        instance.put("@r", 1.0);
        instance.put("@h", Math.sqrt(3.0));
        EmbedEvalUnit unit = result.parse(script);
        IRubyObject ret = unit.run();
        List<Double> rightCircularCone = (List<Double>) ret.toJava(List.class);
        assertEquals(1.813799, rightCircularCone.get(0), 0.000001);
        assertEquals(9.424778, rightCircularCone.get(1), 0.000001);

        instance.getVarMap().clear();
        instance = null;
View Full Code Here

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

        IRubyObject val = value;
        if(val.dataGetStruct() instanceof JavaObject) {
            val = (IRubyObject)val.dataGetStruct();
        }
        try {
            Object convertedValue = val.toJava(field.getType());

            field.set(javaObject, convertedValue);
        } catch (IllegalAccessException iae) {
            throw getRuntime().newTypeError(
                                "illegal access on setting variable: " + iae.getMessage());
View Full Code Here

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

    }

    @Override
    public Object get(Object key) {
        IRubyObject gotten = internalGet(JavaUtil.convertJavaToUsableRubyObject(getRuntime(), key));
        return gotten == null ? null : gotten.toJava(Object.class);
    }

    @Override
    public Object put(Object key, Object value) {
        internalPut(JavaUtil.convertJavaToUsableRubyObject(getRuntime(), key), JavaUtil.convertJavaToUsableRubyObject(getRuntime(), value));
View Full Code Here

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

        }

        public Object next() {
            IRubyObject element = elt(index);
            last = index++;
            return element.toJava(Object.class);
        }

        public void remove() {
            if (last == -1) throw new IllegalStateException();
View Full Code Here

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

        Object[] converted = new Object[count];
       
        for (int i = 0; i < count; i++) {
            // TODO: call ruby method
            IRubyObject ith = constructor_args.aref(getRuntime().newFixnum(i));
            converted[i] = ith.toJava(parameterTypes[i]);
        }

        JavaProxyInvocationHandler handler = new JavaProxyInvocationHandler() {
            public IRubyObject getOrig() {
                return self;
View Full Code Here

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

                    throw runtime.newArgumentError(newArgs.length, v);
                }
                if (m.getReturnType() == void.class) {
                    return null;
                } else {
                    return result.toJava(m.getReturnType());
                }
            }
        };

        try {
View Full Code Here

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

        int count = (int) constructor_args.length().getLongValue();
        Object[] converted = new Object[count];
        for (int i = 0; i < count; i++) {
            // TODO: call ruby method
            IRubyObject ith = constructor_args.aref(getRuntime().newFixnum(i));
            converted[i] = ith.toJava(parameterTypes[i]);
        }

        final IRubyObject recv = this;

        JavaProxyInvocationHandler handler = new JavaProxyInvocationHandler() {
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.