@Test public void shouldProperlyHandleDeclaredMethodsInRubyModules() throws Exception { final ScriptingContainer ruby = createRubyInstance(); final RubyKlassNavigator navigator = new RubyKlassNavigator(ruby.getProvider().getRuntime(), ClassLoader.getSystemClassLoader()); final MyRubyModule myModule = new MyRubyModule(ruby.getRuntime(), new MyRubyClass(ruby.getRuntime()), true); final Klass<RubyModule> classInstance = new Klass<RubyModule>(myModule, navigator); final List<MethodRef> declaredMethods = classInstance.getDeclaredMethods(); for (MethodRef ref : declaredMethods) { if (ref instanceof RubyMethodRef) { if ("doDynamic".equals(ref.getName())) { return; } } } Assert.fail("Have not found 'doDynamic' in the returned function list"); }
@Override public List<MethodRef> getDeclaredMethods(RubyModule clazz) { List<MethodRef> r = new ArrayList<MethodRef>(); for (DynamicMethod m : clazz.getMethods().values()) { if (m.getImplementationClass()==clazz) r.add(new RubyMethodRef(clazz,m)); } return r; }
RubyKlassNavigator extends KlassNavigator<RubyModule> { @Override public List<MethodRef> getDeclaredMethods(RubyModule clazz) { List<MethodRef> r = new ArrayList<MethodRef>(); for (DynamicMethod m : clazz.getMethods().values()) { if (m.getImplementationClass()==clazz) r.add(new RubyMethodRef(clazz,m)); } return r; } }
RubyKlassNavigator extends KlassNavigator<RubyModule> { @Override public List<MethodRef> getDeclaredMethods(RubyModule clazz) { List<MethodRef> r = new ArrayList<MethodRef>(); for (DynamicMethod m : clazz.getMethods().values()) { if (m.getImplementationClass()==clazz) r.add(new RubyMethodRef(clazz,m)); } return r; } RubyKlassNavigator(Ruby ruby, ClassLoader cl); }
RubyKlassNavigator extends KlassNavigator<RubyModule> { @Override public List<MethodRef> getDeclaredMethods(RubyModule clazz) { List<MethodRef> r = new ArrayList<MethodRef>(); for (DynamicMethod m : clazz.getMethods().values()) { if (m.getImplementationClass()==clazz) r.add(new RubyMethodRef(clazz,m)); } return r; } RubyKlassNavigator(Ruby ruby, ClassLoader cl); @Override URL getResource(RubyModule clazz, String resourceName); @Override Iterable<Klass<?>> getAncestors(RubyModule clazz); @Override Klass<?> getSuperClass(RubyModule clazz); @Override List<MethodRef> getDeclaredMethods(RubyModule clazz); @Override List<FieldRef> getDeclaredFields(RubyModule clazz); @Override List<Function> getFunctions(RubyModule clazz); @Override Class toJavaClass(RubyModule clazz); Klass<RubyModule> wrap(RubyModule m); }
RubyKlassNavigator extends KlassNavigator<RubyModule> { @Override public List<MethodRef> getDeclaredMethods(RubyModule clazz) { List<MethodRef> r = new ArrayList<MethodRef>(); for (DynamicMethod m : clazz.getMethods().values()) { if (m.getImplementationClass()==clazz) r.add(new RubyMethodRef(clazz,m)); } return r; } RubyKlassNavigator(Ruby ruby, ClassLoader cl); @Override URL getResource(RubyModule clazz, String resourceName); @Override Iterable<Klass<?>> getAncestors(RubyModule clazz); @Override Klass<?> getSuperClass(RubyModule clazz); @Override List<MethodRef> getDeclaredMethods(RubyModule clazz); @Override List<FieldRef> getDeclaredFields(RubyModule clazz); @Override List<Function> getFunctions(RubyModule clazz); @Override Class toJavaClass(RubyModule clazz); Klass<RubyModule> wrap(RubyModule m);  }