Package org.jruby

Examples of org.jruby.RubyModule.addMethod()


        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


       
        DefaultMethod newMethod = new DefaultMethod(containingClass, scope,
                body, (ArgsNode) 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

        runtime.getKernel().defineAnnotatedMethods(MiniJava.class);

        // load up object and add a few useful methods
        RubyModule javaObject = getMirrorForClass(runtime, Object.class);

        javaObject.addMethod("to_s", new JavaMethod.JavaMethodZero(javaObject, Visibility.PUBLIC) {
            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
                return context.getRuntime().newString(((JavaObjectWrapper) self).object.toString());
            }
        });
View Full Code Here

            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
                return context.getRuntime().newString(((JavaObjectWrapper) self).object.toString());
            }
        });

        javaObject.addMethod("hash", new JavaMethod.JavaMethodZero(javaObject, Visibility.PUBLIC) {
            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
                return self.getRuntime().newFixnum(((JavaObjectWrapper) self).object.hashCode());
            }
        });
View Full Code Here

            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
                return self.getRuntime().newFixnum(((JavaObjectWrapper) self).object.hashCode());
            }
        });

        javaObject.addMethod("==", new JavaMethod.JavaMethodOne(javaObject, Visibility.PUBLIC) {
            @Override
            public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg) {
                if (arg instanceof JavaObjectWrapper) {
                    return context.getRuntime().newBoolean(((JavaObjectWrapper) self).object.equals(((JavaObjectWrapper) arg).object));
                } else {
View Full Code Here

            DynamicMethod dynMethod = factory.createMethod(target, method);

            // if not overloaded, we add a method that guesses at which signature to use
            // TODO: just adding first one right now...add in signature-guessing logic
            if (target.getMethods().get(name) == null) {
                target.addMethod(name, dynMethod);
            }

            // add method with full signature, so it's guaranteed to be directly accessible
            // TODO: no need for this to be a full, formal JVM signature
            name = name + prettyParams(method.getParameterTypes());
View Full Code Here

            }

            // add method with full signature, so it's guaranteed to be directly accessible
            // TODO: no need for this to be a full, formal JVM signature
            name = name + prettyParams(method.getParameterTypes());
            target.addMethod(name, dynMethod);
        }
    }
   
    private static void populateSpecialMethods(RubyModule rubyMod, RubyModule rubySing, final Class cls) {
        final Ruby ruby = rubyMod.getRuntime();
View Full Code Here

                staticScope.setVariables(new String[cmethod.locals]);
                staticScope.determineModule();

                RubiniusMethod newMethod = new RubiniusMethod(clzz, cmethod, staticScope, visibility);

                clzz.addMethod(name, newMethod);
   
                if (context.getCurrentVisibility() == Visibility.MODULE_FUNCTION) {
                    clzz.getSingletonClass().addMethod(
                            name,
                            new WrapperMethod(clzz.getSingletonClass(), newMethod,
View Full Code Here

                StaticScope sco = new LocalStaticScope(null);
                sco.setVariables(bytecodes[ip].iseq_op.locals);
                YARVMethod newMethod = new YARVMethod(containingClass, bytecodes[ip].iseq_op, sco, visibility);

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

                containingClass.addMethod(mname, newMethod);
   
                if (context.getCurrentVisibility() == Visibility.MODULE_FUNCTION) {
                    RubyModule singleton = containingClass.getSingletonClass();
                    singleton.addMethod(mname, new WrapperMethod(singleton, newMethod, Visibility.PUBLIC));
                    containingClass.callMethod(context, "singleton_method_added", runtime.fastNewSymbol(mname));
                }
   
                // 'class << state.self' and 'class << obj' uses defn as opposed to defs
                if (containingClass.isSingleton()) {
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.