Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jruby.runtime.scope;
 
 import org.jruby.Ruby;
This is a DynamicScope that does not support any variables. It differs from NoVarsDynamicScope in that it has hard failures for "backref" and "lastline" accesses, since in the JRuby 1.3 cycle it was discovered that threads were sharing a single dummyscope while still setting per-call backrefs. The hard errors here are an attempt to catch such situations in the future, before the optimizing compiler work makes such determinations in advance.
public class DummyDynamicScope extends NoVarsDynamicScope {
    private static final int SIZE = 0;
    private static final String GROW_ERROR = "DummyDynamicScope cannot be grown; use ManyVarsDynamicScope";
    
    public DummyDynamicScope(StaticScope staticScopeDynamicScope parent) {
        super(staticScopeparent);
    }
    public DummyDynamicScope(StaticScope staticScope) {
        super(staticScope);
    }
    
    public void growIfNeeded() {
        growIfNeeded();
    }
    protected void growIfNeeded(int sizeString message) {
        if (.getNumberOfVariables() != size) {
            throw new RuntimeException(message);
        }
    }
    
    public DynamicScope cloneScope() {
        return new DummyDynamicScope();
    }

    
Get backref
    public IRubyObject getBackRef(Ruby runtime) {
        if (!.isBackrefLastlineScope()) {
            return .getBackRef(runtime);
        }
        if (runtime.getDebug().isTrue()) {
            runtime.getWarnings().warn("DummyDynamicScope should never be used for backref storage");
        }
        return runtime.getNil();
    }

    
Set backref
    public IRubyObject setBackRef(IRubyObject backref) {
        if (!.isBackrefLastlineScope()) {
            return .setBackRef(backref);
        }
        if (backref.getRuntime().getDebug().isTrue()) {
            backref.getRuntime().getWarnings().warn("DummyDynamicScope should never be used for backref storage");
        }
        return backref;
    }

    
Get lastline
    public IRubyObject getLastLine(Ruby runtime) {
        if (!.isBackrefLastlineScope()) {
            return .getLastLine(runtime);
        }
        if (runtime.getDebug().isTrue()) {
            runtime.getWarnings().warn("DummyDynamicScope should never be used for lastline storage");
        }
        return runtime.getNil();
    }

    
Set lastline
    public IRubyObject setLastLine(IRubyObject lastline) {
        if (!.isBackrefLastlineScope()) {
            return .setLastLine(lastline);
        }
        if (lastline.getRuntime().getDebug().isTrue()) {
            lastline.getRuntime().getWarnings().warn("DummyDynamicScope should never be used for backref storage");
        }
        return lastline;
    }
New to GrepCode? Check out our FAQ X