Package org.jruby

Examples of org.jruby.RubyModule.addMethod()


        DynamicMethod newMethod = DynamicMethodFactory.newDefaultMethod(
                runtime, containingClass, name, scope, body, argsNode,
                visibility, getPosition());
  
        containingClass.addMethod(name, newMethod);
  
        if (context.getCurrentVisibility() == Visibility.MODULE_FUNCTION) {
            containingClass.getSingletonClass().addMethod(name,
                    new WrapperMethod(containingClass.getSingletonClass(), newMethod, Visibility.PUBLIC));
           
View Full Code Here


    }

    @Override
    public Label interpret(InterpreterContext interp, IRubyObject self) {
        RubyModule clazz = (RubyModule) method.getContainer().retrieve(interp);
        clazz.addMethod(method.getName(), new InterpretedIRMethod(method, clazz));
        return null;
    }
}
View Full Code Here

        for (int i = 0; i < javaInstanceMethods.length; i++) {
            Method method = javaInstanceMethods[i];
            String name = method.getName();
            if (targetModule.searchMethod(name) != UndefinedMethod.INSTANCE) continue;
           
            targetModule.addMethod(name, dummyMethod);
        }
       
        return runtime.getNil();
    }
View Full Code Here

        if ("initialize".equals(name) || "initialize_copy".equals(name) || visibility == Visibility.MODULE_FUNCTION) {
            visibility = Visibility.PRIVATE;
        }

        DynamicMethod newMethod = new InterpretedIRMethod(method, visibility, clazz);
        clazz.addMethod(name, newMethod);
        //System.out.println("Added " + name + " to " + clazz + "; self is " + self);

        if (context.getCurrentVisibility() == Visibility.MODULE_FUNCTION) {
            clazz.getSingletonClass().addMethod(name, new WrapperMethod(clazz.getSingletonClass(), newMethod, Visibility.PUBLIC));
            clazz.callMethod(context, "singleton_method_added", runtime.fastNewSymbol(name));
View Full Code Here

                    // FIXME: Organizationally this might be nicer in a specialized class
                    if (c.getComponentType() == byte.class) {
                        final Encoding ascii8bit = runtime.getEncodingService().getAscii8bitEncoding();
                       
                        // All bytes can be considered raw strings and forced to particular codings if not 8bitascii
                        proxyClass.addMethod("to_s", new JavaMethodZero(proxyClass, PUBLIC) {
                            @Override
                            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
                                ByteList bytes = new ByteList((byte[]) ((ArrayJavaProxy) self).getObject(), ascii8bit);
                                return RubyString.newStringLight(context.runtime, bytes);
                            }
View Full Code Here

        for (int i = 0; i < javaInstanceMethods.length; i++) {
            Method method = javaInstanceMethods[i];
            String name = method.getName();
            if (targetModule.searchMethod(name) != UndefinedMethod.INSTANCE) continue;
           
            targetModule.addMethod(name, dummyMethod);
        }
       
        return runtime.getNil();
    }
View Full Code Here

                } else {
                    return runtime.getNil();
                }
            }
        };
        readlineM.addMethod("readline", readlineMethod);
        readlineM.getSingletonClass().addMethod("readline", readlineMethod);
    }

    /**
     * Hooks this <code>TextAreaReadline</code> instance into the
View Full Code Here

                    // FIXME: Organizationally this might be nicer in a specialized class
                    if (c.getComponentType() == byte.class) {
                        final Encoding ascii8bit = runtime.getEncodingService().getAscii8bitEncoding();
                       
                        // All bytes can be considered raw strings and forced to particular codings if not 8bitascii
                        proxyClass.addMethod("to_s", new JavaMethodZero(proxyClass, PUBLIC) {
                            @Override
                            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
                                ByteList bytes = new ByteList((byte[]) ((ArrayJavaProxy) self).getObject(), ascii8bit);
                                return RubyString.newStringLight(context.runtime, bytes);
                            }
View Full Code Here

        for (int i = 0; i < javaInstanceMethods.length; i++) {
            Method method = javaInstanceMethods[i];
            String name = method.getName();
            if (targetModule.searchMethod(name) != UndefinedMethod.INSTANCE) continue;
           
            targetModule.addMethod(name, dummyMethod);
        }
       
        return runtime.getNil();
    }
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.