GlobalVariable.java

  1. package org.jruby.ir.operands;

  2. import org.jruby.ir.IRVisitor;
  3. import org.jruby.ir.Interp;
  4. import org.jruby.parser.StaticScope;
  5. import org.jruby.runtime.DynamicScope;
  6. import org.jruby.runtime.ThreadContext;
  7. import org.jruby.runtime.builtin.IRubyObject;

  8. public class GlobalVariable extends Reference {
  9.     public GlobalVariable(String name) {
  10.         super(OperandType.GLOBAL_VARIABLE, name);
  11.     }

  12.     public int compareTo(Object arg0) {
  13.         // ENEBO: what should compareTo when it is not comparable?
  14.         if (!(arg0 instanceof GlobalVariable)) return 0;

  15.         return getName().compareTo(((GlobalVariable) arg0).getName());
  16.     }

  17.     @Interp
  18.     @Override
  19.     public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
  20.         return context.runtime.getGlobalVariables().get(getName());
  21.     }

  22.     @Override
  23.     public void visit(IRVisitor visitor) {
  24.         visitor.GlobalVariable(this);
  25.     }
  26. }