public List<IRubyObject> getAncestorList() { ArrayList<IRubyObject> list = new ArrayList<IRubyObject>(); for (RubyModule module = this; module != null; module = module.getSuperClass()) { if(!module.isSingleton()) list.add(module.getNonIncludedClass()); } return list; }
public List<IRubyObject> getAncestorList() { ArrayList<IRubyObject> list = new ArrayList<IRubyObject>(); for (RubyModule module = this; module != null; module = module.getSuperClass()) { if(!module.isSingleton()) list.add(module.getNonIncludedClass()); } return list; }
@JRubyMethod(name = "singleton_class?") public IRubyObject singleton_class_p(ThreadContext context) { return context.runtime.newBoolean(isSingleton()); }
@JRubyMethod(name = "singleton_class?") public IRubyObject singleton_class_p(ThreadContext context) { return context.runtime.newBoolean(isSingleton()); }
private static void callNormalMethodHook(RubyModule containingClass, ThreadContext context, RubySymbol name) { // 'class << state.self' and 'class << obj' uses defn as opposed to defs if (containingClass.isSingleton()) { callSingletonMethodHook(((MetaClass) containingClass).getAttached(), context, name); } else { containingClass.callMethod(context, "method_added", name); } }
private static void callNormalMethodHook(RubyModule containingClass, ThreadContext context, RubySymbol name) { // 'class << state.self' and 'class << obj' uses defn as opposed to defs if (containingClass.isSingleton()) { callSingletonMethodHook(((MetaClass) containingClass).getAttached(), context, name); } else { containingClass.callMethod(context, "method_added", name); } }
private static void callNormalMethodHook(RubyModule containingClass, ThreadContext context, RubySymbol name) { // 'class << state.self' and 'class << obj' uses defn as opposed to defs if (containingClass.isSingleton()) { callSingletonMethodHook(((MetaClass) containingClass).getAttached(), context, name); } else { containingClass.callMethod(context, "method_added", name); } }
private static void callNormalMethodHook(RubyModule containingClass, ThreadContext context, RubySymbol name) { // 'class << state.self' and 'class << obj' uses defn as opposed to defs if (containingClass.isSingleton()) { callSingletonMethodHook(((MetaClass) containingClass).getAttached(), context, name); } else { containingClass.callMethod(context, "method_added", name); } }
@JIT @Interp public static IRubyObject isDefinedClassVar(ThreadContext context, RubyModule receiver, String name, IRubyObject definedMessage) { boolean defined = receiver.isClassVarDefined(name); if (!defined && receiver.isSingleton()) { // Look for class var in singleton if it is one. IRubyObject attached = ((MetaClass) receiver).getAttached(); if (attached instanceof RubyModule) defined = ((RubyModule) attached).isClassVarDefined(name); } return defined ? definedMessage : context.nil; }
@JIT @Interp public static IRubyObject isDefinedClassVar(ThreadContext context, RubyModule receiver, String name, IRubyObject definedMessage) { boolean defined = receiver.isClassVarDefined(name); if (!defined && receiver.isSingleton()) { // Look for class var in singleton if it is one. IRubyObject attached = ((MetaClass) receiver).getAttached(); if (attached instanceof RubyModule) defined = ((RubyModule) attached).isClassVarDefined(name); } return defined ? definedMessage : context.nil; }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) { Ruby runtime = context.runtime; RubyModule cm = (RubyModule) getObject().retrieve(context, self, currDynScope, temp); String name = getName().string; boolean defined = cm.isClassVarDefined(name); if (!defined && cm.isSingleton()) { // Not found look for cvar on singleton IRubyObject attached = ((MetaClass)cm).getAttached(); if (attached instanceof RubyModule) defined = ((RubyModule)attached).isClassVarDefined(name); } return runtime.newBoolean(defined); }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) { Ruby runtime = context.runtime; RubyModule cm = (RubyModule) getObject().retrieve(context, self, currDynScope, temp); String name = getName().string; boolean defined = cm.isClassVarDefined(name); if (!defined && cm.isSingleton()) { // Not found look for cvar on singleton IRubyObject attached = ((MetaClass)cm).getAttached(); if (attached instanceof RubyModule) defined = ((RubyModule)attached).isClassVarDefined(name); } return runtime.newBoolean(defined); }
public static RubyModule getClassVariableBase(Ruby runtime, StaticScope scope) { RubyModule rubyClass = scope.getModule(); while (rubyClass.isSingleton() || rubyClass == runtime.getDummy()) { // We ran out of scopes to check if (scope == null) return null; scope = scope.getPreviousCRefScope(); rubyClass = scope.getModule(); if (scope.getPreviousCRefScope() == null) { runtime.getWarnings().warn(ID.CVAR_FROM_TOPLEVEL_SINGLETON_METHOD, "class variable access from toplevel singleton method"); } } return rubyClass; }
public static RubyModule getClassVariableBase(Ruby runtime, StaticScope scope) { RubyModule rubyClass = scope.getModule(); while (rubyClass.isSingleton() || rubyClass == runtime.getDummy()) { // We ran out of scopes to check if (scope == null) return null; scope = scope.getPreviousCRefScope(); rubyClass = scope.getModule(); if (scope.getPreviousCRefScope() == null) { runtime.getWarnings().warn(ID.CVAR_FROM_TOPLEVEL_SINGLETON_METHOD, "class variable access from toplevel singleton method"); } } return rubyClass; }
@Override public IRubyObject assign(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject value, Block block, boolean checkArity) { if (runtime.isVerbose() && context.getRubyClass().isSingleton()) { runtime.getWarnings().warn(ID.DECLARING_SCLASS_VARIABLE, getPosition(), "Declaring singleton class variable."); } ASTInterpreter.getClassVariableBase(context, runtime).setClassVar(name, value); return runtime.getNil(); } }
@Override public IRubyObject assign(Ruby runtime, ThreadContext context, IRubyObject self, IRubyObject value, Block block, boolean checkArity) { if (runtime.isVerbose() && context.getRubyClass().isSingleton()) { runtime.getWarnings().warn(ID.DECLARING_SCLASS_VARIABLE, getPosition(), "Declaring singleton class variable."); } ASTInterpreter.getClassVariableBase(context, runtime).setClassVar(name, value); return runtime.getNil(); } }
@JRubyMethod(name = "alias_method", required = 2, visibility = PRIVATE) public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) { String newName = newId.asJavaString(); defineAlias(newName, oldId.asJavaString()); RubySymbol newSym = newId instanceof RubySymbol ? (RubySymbol)newId : context.runtime.newSymbol(newName); if (isSingleton()) { ((MetaClass)this).getAttached().callMethod(context, "singleton_method_added", newSym); } else { callMethod(context, "method_added", newSym); } return this; }
@JRubyMethod(name = "alias_method", required = 2, visibility = PRIVATE) public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) { String newName = newId.asJavaString(); defineAlias(newName, oldId.asJavaString()); RubySymbol newSym = newId instanceof RubySymbol ? (RubySymbol)newId : context.runtime.newSymbol(newName); if (isSingleton()) { ((MetaClass)this).getAttached().callMethod(context, "singleton_method_added", newSym); } else { callMethod(context, "method_added", newSym); } return this; }
@JRubyMethod(name = "alias_method", required = 2) public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) { RubySymbol newSym = TypeConverter.checkID(newId); RubySymbol oldSym = TypeConverter.checkID(oldId); // MRI uses rb_to_id but we return existing symbol defineAlias(newSym.idString(), oldSym.idString()); if (isSingleton()) { ((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym); } else { callMethod(context, "method_added", newSym); } return this; }
@JRubyMethod(name = "alias_method", required = 2) public RubyModule alias_method(ThreadContext context, IRubyObject newId, IRubyObject oldId) { RubySymbol newSym = TypeConverter.checkID(newId); RubySymbol oldSym = TypeConverter.checkID(oldId); // MRI uses rb_to_id but we return existing symbol defineAlias(newSym.idString(), oldSym.idString()); if (isSingleton()) { ((MetaClass) this).getAttached().callMethod(context, "singleton_method_added", newSym); } else { callMethod(context, "method_added", newSym); } return this; }