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; }
@JRubyMethod(name = "used_modules", reads = SCOPE) public IRubyObject used_modules(ThreadContext context) { StaticScope cref = context.getCurrentStaticScope(); RubyArray ary = context.runtime.newArray(); while (cref != null) { RubyModule overlay; if ((overlay = cref.getOverlayModuleForRead()) != null && !overlay.refinements.isEmpty()) { overlay.refinements.entrySet().stream().forEach(entry -> { RubyModule mod = entry.getValue(); while (mod != null && mod.isRefinement()) { ary.push(mod.definedAt); mod = mod.getSuperClass(); } }); } cref = cref.getPreviousCRefScope(); } return ary; }
@JRubyMethod(name = "used_modules", reads = SCOPE) public IRubyObject used_modules(ThreadContext context) { StaticScope cref = context.getCurrentStaticScope(); RubyArray ary = context.runtime.newArray(); while (cref != null) { RubyModule overlay; if ((overlay = cref.getOverlayModuleForRead()) != null && !overlay.refinements.isEmpty()) { overlay.refinements.entrySet().stream().forEach(entry -> { RubyModule mod = entry.getValue(); while (mod != null && mod.isRefinement()) { ary.push(mod.definedAt); mod = mod.getSuperClass(); } }); } cref = cref.getPreviousCRefScope(); } return ary; }
public static RubyModule getModuleFromScope(ThreadContext context, StaticScope scope, IRubyObject arg) { Ruby runtime = context.runtime; RubyModule rubyClass = scope.getModule(); // SSS FIXME: Copied from ASTInterpreter.getClassVariableBase and adapted while (scope != null && (rubyClass.isSingleton() || rubyClass == runtime.getDummy())) { scope = scope.getPreviousCRefScope(); rubyClass = scope.getModule(); if (scope.getPreviousCRefScope() == null) { runtime.getWarnings().warn(IRubyWarnings.ID.CVAR_FROM_TOPLEVEL_SINGLETON_METHOD, "class variable access from toplevel singleton method"); } } if ((scope == null) && (arg != null)) { // We ran out of scopes to check -- look in arg's metaclass rubyClass = arg.getMetaClass(); } if (rubyClass == null) { throw context.runtime.newTypeError("no class/module to define class variable"); } return rubyClass; }
public static RubyModule getModuleFromScope(ThreadContext context, StaticScope scope, IRubyObject arg) { Ruby runtime = context.runtime; RubyModule rubyClass = scope.getModule(); // SSS FIXME: Copied from ASTInterpreter.getClassVariableBase and adapted while (scope != null && (rubyClass.isSingleton() || rubyClass == runtime.getDummy())) { scope = scope.getPreviousCRefScope(); rubyClass = scope.getModule(); if (scope.getPreviousCRefScope() == null) { runtime.getWarnings().warn(IRubyWarnings.ID.CVAR_FROM_TOPLEVEL_SINGLETON_METHOD, "class variable access from toplevel singleton method"); } } if ((scope == null) && (arg != null)) { // We ran out of scopes to check -- look in arg's metaclass rubyClass = arg.getMetaClass(); } if (rubyClass == null) { throw context.runtime.newTypeError("no class/module to define class variable"); } return rubyClass; }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) { Ruby runtime = context.runtime; StaticScope scope = (StaticScope) startingScope.retrieve(context, self, currDynScope, temp); RubyModule rubyClass = scope.getModule(); // SSS FIXME: Copied from ASTInterpreter.getClassVariableBase and adapted while (scope != null && (rubyClass.isSingleton() || rubyClass == runtime.getDummy())) { 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"); } } if ((scope == null) && (object != null)) { // We ran out of scopes to check -- look in arg's metaclass IRubyObject arg = (IRubyObject) object.retrieve(context, self, currDynScope, temp); rubyClass = arg.getMetaClass(); } if (rubyClass == null) { throw context.runtime.newTypeError("no class/module to define class variable"); } return rubyClass; }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) { Ruby runtime = context.runtime; StaticScope scope = (StaticScope) startingScope.retrieve(context, self, currDynScope, temp); RubyModule rubyClass = scope.getModule(); // SSS FIXME: Copied from ASTInterpreter.getClassVariableBase and adapted while (scope != null && (rubyClass.isSingleton() || rubyClass == runtime.getDummy())) { 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"); } } if ((scope == null) && (object != null)) { // We ran out of scopes to check -- look in arg's metaclass IRubyObject arg = (IRubyObject) object.retrieve(context, self, currDynScope, temp); rubyClass = arg.getMetaClass(); } if (rubyClass == null) { throw context.runtime.newTypeError("no class/module to define class variable"); } return rubyClass; }
/** * Return an array of nested modules or classes. */ @JRubyMethod(name = "nesting", reads = FrameField.SCOPE, meta = true) public static RubyArray nesting(ThreadContext context, IRubyObject recv, Block block) { Ruby runtime = context.runtime; RubyModule object = runtime.getObject(); StaticScope scope = context.getCurrentScope().getStaticScope(); RubyArray result = runtime.newArray(); for (StaticScope current = scope; current.getModule() != object; current = current.getPreviousCRefScope()) { result.append(current.getModule()); } return result; }
/** * Return an array of nested modules or classes. */ @JRubyMethod(name = "nesting", reads = FrameField.SCOPE, meta = true) public static RubyArray nesting(ThreadContext context, IRubyObject recv, Block block) { Ruby runtime = context.runtime; RubyModule object = runtime.getObject(); StaticScope scope = context.getCurrentScope().getStaticScope(); RubyArray result = runtime.newArray(); for (StaticScope current = scope; current.getModule() != object; current = current.getPreviousCRefScope()) { result.append(current.getModule()); } return result; }
/** * Return an array of nested modules or classes. */ @JRubyMethod(name = "nesting", reads = SCOPE, meta = true) public static RubyArray nesting(ThreadContext context, IRubyObject recv, Block block) { Ruby runtime = context.runtime; RubyModule object = runtime.getObject(); StaticScope scope = context.getCurrentScope().getStaticScope(); RubyArray result = runtime.newArray(); for (StaticScope current = scope; current.getModule() != object; current = current.getPreviousCRefScope()) { result.append(current.getModule()); } return result; }
/** * Return an array of nested modules or classes. */ @JRubyMethod(name = "nesting", reads = SCOPE, meta = true) public static RubyArray nesting(ThreadContext context, IRubyObject recv, Block block) { Ruby runtime = context.runtime; RubyModule object = runtime.getObject(); StaticScope scope = context.getCurrentScope().getStaticScope(); RubyArray result = runtime.newArray(); for (StaticScope current = scope; current.getModule() != object; current = current.getPreviousCRefScope()) { result.append(current.getModule()); } return result; }
newScope.setPreviousCRefScope(oldScope.getPreviousCRefScope()); newScope.setModule(oldScope.getModule()); block.getBody().setStaticScope(newScope);
newScope.setPreviousCRefScope(oldScope.getPreviousCRefScope()); newScope.setModule(oldScope.getModule()); block.getBody().setStaticScope(newScope);