Package org.jruby

Examples of org.jruby.RubyProc


    }

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
        if (block.isGiven()) {
            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaMethod method = (JavaMethod)findCallableArityFour(self, name, arg0, arg1, arg2, proc);
            Object cArg0 = convertArg(arg0, method, 0);
            Object cArg1 = convertArg(arg1, method, 1);
            Object cArg2 = convertArg(arg2, method, 2);
            Object cArg3 = convertArg(proc, method, 3);
View Full Code Here


    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
        if (block.isGiven()) {
            JavaProxy proxy = castJavaProxy(self);

            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaConstructor constructor = (JavaConstructor)findCallableArityOne(self, name, proc);
            Object cArg0 = convertArg(proc, constructor, 0);

            proxy.setObject(constructor.newInstanceDirect(context, cArg0));
View Full Code Here

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
        if (block.isGiven()) {
            JavaProxy proxy = castJavaProxy(self);

            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaConstructor constructor = (JavaConstructor)findCallableArityTwo(self, name, arg0, proc);
            Object cArg0 = convertArg(arg0, constructor, 0);
            Object cArg1 = convertArg(proc, constructor, 1);

            proxy.setObject(constructor.newInstanceDirect(context, cArg0, cArg1));
View Full Code Here

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
        if (block.isGiven()) {
            JavaProxy proxy = castJavaProxy(self);

            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaConstructor constructor = (JavaConstructor)findCallableArityThree(self, name, arg0, arg1, proc);
            Object cArg0 = convertArg(arg0, constructor, 0);
            Object cArg1 = convertArg(arg1, constructor, 1);
            Object cArg2 = convertArg(proc, constructor, 2);
View Full Code Here

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
        if (block.isGiven()) {
            JavaProxy proxy = castJavaProxy(self);

            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaConstructor constructor = (JavaConstructor)findCallableArityFour(self, name, arg0, arg1, arg2, proc);
            Object cArg0 = convertArg(arg0, constructor, 0);
            Object cArg1 = convertArg(arg1, constructor, 1);
            Object cArg2 = convertArg(arg2, constructor, 2);
            Object cArg3 = convertArg(proc, constructor, 3);
View Full Code Here

    }

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
        if (block.isGiven()) {
            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaMethod method = (JavaMethod)findCallableArityOne(self, name, proc);
            Object cArg0 = convertArg(proc, method, 0);

            return method.invokeDirect(context, singleton, cArg0);
        } else {
View Full Code Here

    }

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
        if (block.isGiven()) {
            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaMethod method = (JavaMethod)findCallableArityTwo(self, name, arg0, proc);
            Object cArg0 = convertArg(arg0, method, 0);
            Object cArg1 = convertArg(proc, method, 1);

            return method.invokeDirect(context, singleton, cArg0, cArg1);
View Full Code Here

    }

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
        if (block.isGiven()) {
            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaMethod method = (JavaMethod)findCallableArityThree(self, name, arg0, arg1, proc);
            Object cArg0 = convertArg(arg0, method, 0);
            Object cArg1 = convertArg(arg1, method, 1);
            Object cArg2 = convertArg(proc, method, 2);
View Full Code Here

    }

    @Override
    public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
        if (block.isGiven()) {
            RubyProc proc = RubyProc.newProc(context.runtime, block, block.type);
            JavaMethod method = (JavaMethod)findCallableArityFour(self, name, arg0, arg1, arg2, proc);
            Object cArg0 = convertArg(arg0, method, 0);
            Object cArg1 = convertArg(arg1, method, 1);
            Object cArg2 = convertArg(arg2, method, 2);
            Object cArg3 = convertArg(proc, method, 3);
View Full Code Here

    }

    @JRubyMethod(required = 1, optional = 1)
    public RubyObject new_instance(IRubyObject[] args, Block block) {
        int size = Arity.checkArgumentCount(getRuntime(), args, 1, 2) - 1;
        final RubyProc proc;

        // Is there a supplied proc argument or do we assume a block was
        // supplied
        if (args[size] instanceof RubyProc) {
            proc = (RubyProc) args[size];
        } else {
            proc = getRuntime().newProc(Block.Type.PROC,block);
            size++;
        }

        RubyArray constructor_args = (RubyArray) args[0];
        Class<?>[] parameterTypes = getParameterTypes();

        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() {
            public IRubyObject getOrig() {
                return null;
            }

            public Object invoke(Object proxy, JavaProxyMethod method,
                    Object[] nargs) throws Throwable {
                int length = nargs == null ? 0 : nargs.length;
                IRubyObject[] rubyArgs = new IRubyObject[length + 2];
                rubyArgs[0] = JavaObject.wrap(recv.getRuntime(), proxy);
                rubyArgs[1] = method;
                for (int i = 0; i < length; i++) {
                    rubyArgs[i + 2] = JavaUtil.convertJavaToRuby(getRuntime(),
                            nargs[i]);
                }
                IRubyObject call_result = proc.call(getRuntime().getCurrentContext(), rubyArgs);
                Object converted_result = call_result.toJava(method.getReturnType());
                return converted_result;
            }

        };
View Full Code Here

TOP

Related Classes of org.jruby.RubyProc

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.