Package org.jruby

Examples of org.jruby.RubyMethod


    private final RubyMethod method;
    private final String filename;
    private final int line;
   
    public static Block createMethodBlock(ThreadContext context, IRubyObject self, DynamicScope dynamicScope, MethodBlock body) {
        RubyMethod method = body.method;
        RubyModule module = method.getMethod().getImplementationClass();
        Frame frame = new Frame();

        frame.setKlazz(module);
        frame.setName(method.getMethodName());
        frame.setSelf(method.receiver(context));
        frame.setVisibility(method.getMethod().getVisibility());
       
        Binding binding = new Binding(
                frame,
                module,
                dynamicScope,
                new BacktraceElement(module.getName(), method.getMethodName(), body.getFile(), body.getLine()));

        return new Block(body, binding);
    }
View Full Code Here


    }

    public static IRubyObject newProc(Ruby runtime, long fn) {
        String name = System.currentTimeMillis() + "$block_jruby-cext";
        IRubyObject recv = runtime.getCurrentContext().getFrameSelf();
        RubyMethod method = RubyMethod.newMethod(recv.getMetaClass(), name, recv.getMetaClass(), name,
                new NativeProcMethod(recv.getMetaClass(), fn), recv);
        IRubyObject proc = method.to_proc(runtime.getCurrentContext(), Block.NULL_BLOCK);
        return proc;
    }
View Full Code Here

            if (!self.getMetaClass().searchMethod(methodName).isUndefined()) {
                return (RubyMethod)((RubyObject)self).method(name);
            }

            // try to get method from delegated object
            final RubyMethod method = (RubyMethod)((RubyObject)object).method(name);
            return RubyMethod.newMethod(self.getMetaClass(), methodName, self.getMetaClass(), methodName, new JavaMethodNBlock(self.getMetaClass(), Visibility.PUBLIC) {
                @Override
                public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
                    if (self.callMethod(context, "__getobj__") != object) {
                        throw context.getRuntime().newNameError("object changed", "object changed");
                    }
                    return method.call(context, args, block);
                }
            }, self);
        }
View Full Code Here

    }

    public static IRubyObject newProc(Ruby runtime, long fn) {
        String name = System.currentTimeMillis() + "$block_jruby-cext";
        IRubyObject recv = runtime.getCurrentContext().getFrameSelf();
        RubyMethod method = RubyMethod.newMethod(recv.getMetaClass(), name, recv.getMetaClass(), name,
                new NativeProcMethod(recv.getMetaClass(), fn), recv);
        IRubyObject proc = method.to_proc(runtime.getCurrentContext(), Block.NULL_BLOCK);
        return proc;
    }
View Full Code Here

    private final RubyMethod method;
    private final String filename;
    private final int line;
   
    public static Block createMethodBlock(ThreadContext context, IRubyObject self, DynamicScope dynamicScope, MethodBlock body) {
        RubyMethod method = body.method;
        RubyModule module = method.getMethod().getImplementationClass();
        Frame frame = new Frame();

        frame.setKlazz(module);
        frame.setName(method.getMethodName());
        frame.setSelf(method.receiver(context));
        frame.setVisibility(method.getMethod().getVisibility());
       
        Binding binding = new Binding(
                frame,
                module,
                dynamicScope,
                new BacktraceElement(method.getMethodName(), body.getFile(), body.getLine()));

        return new Block(body, binding);
    }
View Full Code Here

   
    public static class MethodExtensions {
        @JRubyMethod(name = "args")
        public static IRubyObject methodArgs(IRubyObject recv) {
            Ruby runtime = recv.getRuntime();
            RubyMethod rubyMethod = (RubyMethod)recv;
            RubyArray argsArray = RubyArray.newArray(runtime);
            DynamicMethod method = rubyMethod.getMethod();
            RubySymbol req = runtime.newSymbol("req");
            RubySymbol opt = runtime.newSymbol("opt");
            RubySymbol rest = runtime.newSymbol("rest");
            RubySymbol block = runtime.newSymbol("block");
View Full Code Here

        // try to get method from self's metaclass
        if (!self.getMetaClass().searchMethod(methodName).isUndefined()) {
            return (RubyMethod) ((RubyObject) self).method(name);
        }
        // try to get method from delegated object
        final RubyMethod method = (RubyMethod) ((RubyObject) object).method(name);
        return RubyMethod.newMethod(self.getMetaClass(), methodName, self.getMetaClass(), methodName, new JavaMethodNBlock(self.getMetaClass(), Visibility.PUBLIC) {

            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
                if (self.callMethod(context, "__getobj__") != object) {
                    throw context.runtime.newNameError("object changed", "object changed");
                }
                return method.call(context, args, block);
            }
        }, self);
    }
View Full Code Here

    private final RubyMethod method;
    private final String filename;
    private final int line;
   
    public static Block createMethodBlock(ThreadContext context, IRubyObject self, DynamicScope dynamicScope, MethodBlock body) {
        RubyMethod method = body.method;
        RubyModule module = method.getMethod().getImplementationClass();
        Frame frame = new Frame();

        frame.setKlazz(module);
        frame.setName(method.getMethodName());
        frame.setSelf(method.receiver(context));
        frame.setVisibility(method.getMethod().getVisibility());
       
        Binding binding = new Binding(
                frame,
                dynamicScope,
                new BacktraceElement(method.getMethodName(), body.getFile(), body.getLine()));

        return new Block(body, binding);
    }
View Full Code Here

   
    public static class MethodExtensions {
        @JRubyMethod(name = "args")
        public static IRubyObject methodArgs(IRubyObject recv) {
            Ruby runtime = recv.getRuntime();
            RubyMethod rubyMethod = (RubyMethod)recv;
            RubyArray argsArray = RubyArray.newArray(runtime);
            DynamicMethod method = rubyMethod.getMethod().getRealMethod();
            RubySymbol req = runtime.newSymbol("req");
            RubySymbol opt = runtime.newSymbol("opt");
            RubySymbol rest = runtime.newSymbol("rest");
            RubySymbol block = runtime.newSymbol("block");
View Full Code Here

TOP

Related Classes of org.jruby.RubyMethod

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.