1 32 package org.jruby.runtime; 33 34 import org.jruby.Ruby; 35 import org.jruby.runtime.builtin.IRubyObject; 36 37 public class GlobalVariable { 38 public static class Copy extends GlobalVariable { 39 private GlobalVariable other; 40 41 public Copy(Ruby runtime, String name, GlobalVariable other) { 42 super(runtime, name, other.get()); 43 this.other = other; 44 } 45 46 public IRubyObject get() { 47 return other.get(); 48 } 49 50 public IRubyObject set(IRubyObject value) { 51 return other.set(value); 52 } 53 } 54 55 protected final Ruby runtime; 56 57 private final String name; 58 private IRubyObject value; 59 60 public static String variableName(String name) { 61 return "$" + name; 62 } 63 64 public GlobalVariable(Ruby runtime, String name, IRubyObject value) { 65 assert name.startsWith("$"); 66 67 this.runtime = runtime; 68 this.name = name; 69 this.value = value; 70 } 71 72 public String name() { 73 return name; 74 } 75 76 public IRubyObject get() { 77 return value; 78 } 79 80 public IRubyObject set(IRubyObject value) { 81 this.value = value; 82 return value; 83 } 84 } 85 | Popular Tags |