1 29 package org.jruby.internal.runtime; 30 31 import org.jruby.Ruby; 32 import org.jruby.runtime.IAccessor; 33 import org.jruby.runtime.builtin.IRubyObject; 34 35 39 public class UndefinedAccessor implements IAccessor { 40 private final Ruby runtime; 41 private final GlobalVariable globalVariable; 42 private final String notInitializedWarning; 43 44 47 public UndefinedAccessor(Ruby runtime, GlobalVariable globalVariable, String name) { 48 assert runtime != null; 49 assert globalVariable != null; 50 assert name != null; 51 52 this.runtime = runtime; 53 this.globalVariable = globalVariable; 54 this.notInitializedWarning = "global variable `" + name + "' not initialized"; 55 } 56 57 60 public IRubyObject getValue() { 61 runtime.getWarnings().warning(notInitializedWarning); 62 return runtime.getNil(); 63 } 64 65 68 public IRubyObject setValue(IRubyObject newValue) { 69 assert newValue != null; 70 globalVariable.setAccessor(new ValueAccessor(newValue)); 71 return newValue; 72 } 73 } 74 | Popular Tags |