private boolean hasConstantInHierarchy(final String name) { for (RubyModule p = this; p != null; p = p.getSuperClass()) { if (p.hasConstant(name)) { return true; } } return false; }
/** * Find the given class in this hierarchy, considering modules along the way. * * @param clazz the class to find * @return The method, or UndefinedMethod if not found */ public RubyModule findImplementer(RubyModule clazz) { for (RubyModule module = this; module != null; module = module.getSuperClass()) { if (module.isSame(clazz)) return module; } return null; }
public boolean hasModuleInPrepends(RubyModule type) { for (RubyModule module = this; module != methodLocation; module = module.getSuperClass()) { if (type == module.getNonIncludedClass()) return true; } return false; }
/** * Find the given class in this hierarchy, considering modules along the way. * * @param clazz the class to find * @return The method, or UndefinedMethod if not found */ public RubyModule findImplementer(RubyModule clazz) { for (RubyModule module = this; module != null; module = module.getSuperClass()) { if (module.isSame(clazz)) return module; } return null; }
private boolean hasConstantInHierarchy(final String name) { for (RubyModule p = this; p != null; p = p.getSuperClass()) { if (p.hasConstant(name)) { return true; } } return false; }
public List<IRubyObject> getAncestorList() { ArrayList<IRubyObject> list = new ArrayList<IRubyObject>(); for (RubyModule module = this; module != null; module = module.getSuperClass()) { // FIXME this is silly. figure out how to delegate the getNonIncludedClass() // call to drop the getDelegate(). if (module.methodLocation == module) list.add(module.getDelegate().getNonIncludedClass()); } return list; }
private RubyClass getAlreadyActivatedRefinementWrapper(RubyClass classWeAreRefining, RubyModule refinement) { // We have already encountered at least one refine on this class. Return that wrapper. RubyClass moduleWrapperForRefinement = activatedRefinements.get(classWeAreRefining); if (moduleWrapperForRefinement == null) return classWeAreRefining; for (RubyModule c = moduleWrapperForRefinement; c != null && c.isIncluded(); c = c.getSuperClass()) { if (c.getNonIncludedClass() == refinement) return null; } return moduleWrapperForRefinement; }
@JRubyMethod(name = "class_variable_defined?", required = 1) public IRubyObject class_variable_defined_p(ThreadContext context, IRubyObject var) { String id = validateClassVariable(context.runtime, var); for (RubyModule module = this; module != null; module = module.getSuperClass()) { if (module.hasClassVariable(id)) return context.tru; } return context.fals; }
@Override protected void addMethodSymbols(Ruby runtime, Set<String> seen, RubyArray ary, boolean not, Visibility visibility) { // IncludedModuleWrapper needs to search prepended modules too, so search until we find methodLocation RubyModule module = origin; RubyModule methodLoc = origin.getMethodLocation(); for (; module != methodLoc; module = module.getSuperClass()) { module.addMethodSymbols(runtime, seen, ary, not, visibility); } // one last add for method location module.addMethodSymbols(runtime, seen, ary, not, visibility); } }
@JIT public static IRubyObject isDefinedSuper(ThreadContext context, IRubyObject receiver, String frameName, RubyModule frameClass, IRubyObject definedMessage) { boolean defined = frameName != null && frameClass != null && Helpers.findImplementerIfNecessary(receiver.getMetaClass(), frameClass).getSuperClass().isMethodBound(frameName, false); return defined ? definedMessage : context.nil; }
@JRubyMethod public IRubyObject super_method(ThreadContext context) { RubyModule superClass = Helpers.findImplementerIfNecessary(receiver.getMetaClass(), implementationModule).getSuperClass(); return super_method(context, receiver, superClass); }
@Interp public static IRubyObject instanceSuper(ThreadContext context, IRubyObject self, String id, RubyModule definingModule, IRubyObject[] args, Block block) { RubyClass superClass = definingModule.getMethodLocation().getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(id) : UndefinedMethod.INSTANCE; IRubyObject rVal = method.isUndefined() ? Helpers.callMethodMissing(context, self, method.getVisibility(), id, CallType.SUPER, args, block) : method.call(context, self, superClass, id, args, block); return rVal; }
private void checkSafeTypeToCopy(RubyClass original) { Ruby runtime = getRuntime(); if (original == runtime.getBasicObject()) throw runtime.newTypeError("can't copy the root class"); if (getSuperClass() == runtime.getBasicObject()) throw runtime.newTypeError("already initialized class"); if (original.isSingleton()) throw runtime.newTypeError("can't copy singleton class"); }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, RubyModule klass, String name, IRubyObject[] args, Block block) { checkSuperDisabledOrOutOfMethod(context, klass, name); RubyClass selfClass = getMetaClass(self); RubyClass superClass = findImplementerIfNecessary(selfClass, klass).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, selfClass, method.getVisibility(), name, CallType.SUPER, args, block); } return method.call(context, self, superClass, name, args, block); }
@Interp public static IRubyObject classSuper(ThreadContext context, IRubyObject self, String id, RubyModule definingModule, IRubyObject[] args, Block block) { RubyClass superClass = definingModule.getMetaClass().getMethodLocation().getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(id) : UndefinedMethod.INSTANCE; IRubyObject rVal = method.isUndefined() ? Helpers.callMethodMissing(context, self, method.getVisibility(), id, CallType.SUPER, args, block) : method.call(context, self, superClass, id, args, block); return rVal; }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, RubyModule klass, String name, IRubyObject arg0, Block block) { checkSuperDisabledOrOutOfMethod(context, klass, name); RubyClass selfClass = getMetaClass(self); RubyClass superClass = findImplementerIfNecessary(selfClass, klass).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, selfClass, method.getVisibility(), name, CallType.SUPER, arg0, block); } return method.call(context, self, superClass, name, arg0, block); }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, IRubyObject arg0, IRubyObject arg1, Block block) { checkSuperDisabledOrOutOfMethod(context); RubyModule klazz = context.getFrameKlazz(); String name = context.getFrameName(); RubyClass selfClass = getMetaClass(self); RubyClass superClass = findImplementerIfNecessary(selfClass, klazz).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, selfClass, method.getVisibility(), name, CallType.SUPER, arg0, arg1, block); } return method.call(context, self, superClass, name, arg0, arg1, block); }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) { checkSuperDisabledOrOutOfMethod(context); RubyModule klazz = context.getFrameKlazz(); String name = context.getFrameName(); RubyClass selfClass = getMetaClass(self); RubyClass superClass = findImplementerIfNecessary(selfClass, klazz).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, selfClass, method.getVisibility(), name, CallType.SUPER, arg0, arg1, arg2, block); } return method.call(context, self, superClass, name, arg0, arg1, arg2, block); }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) { checkSuperDisabledOrOutOfMethod(context); RubyModule klazz = context.getFrameKlazz(); String name = context.getFrameName(); RubyClass selfClass = getMetaClass(self); RubyClass superClass = findImplementerIfNecessary(selfClass, klazz).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, selfClass, method.getVisibility(), name, CallType.SUPER, arg0, arg1, arg2, block); } return method.call(context, self, superClass, name, arg0, arg1, arg2, block); }
public static IRubyObject invokeSuper(ThreadContext context, IRubyObject self, IRubyObject arg0, Block block) { checkSuperDisabledOrOutOfMethod(context); RubyModule klazz = context.getFrameKlazz(); String name = context.getFrameName(); RubyClass selfClass = getMetaClass(self); RubyClass superClass = findImplementerIfNecessary(selfClass, klazz).getSuperClass(); DynamicMethod method = superClass != null ? superClass.searchMethod(name) : UndefinedMethod.INSTANCE; if (method.isUndefined()) { return callMethodMissing(context, self, selfClass, method.getVisibility(), name, CallType.SUPER, arg0, block); } return method.call(context, self, superClass, name, arg0, block); }