4 # Stores global variables and global variable aliases.
11 @internal = LookupTable.new(
13 :$/ => "\n", # Input record separator
14 :$\ => nil, # Output record separator
17 :$LOAD_PATH => load_path,
18 :$" => loaded_features,
19 :$LOADED_FEATURES => loaded_features,
20 :$, => '', # Output field separator
27 :$. => 0, # TODO: Last line number of IO read.
28 :$_ => nil, # HACK: bunk for now.
29 :$< => nil, # HACK: should be ARGF
30 :$? => nil, # Process status. nil until set
31 :$= => false # ignore case, whatever that is
34 @alias = LookupTable.new
35 @hooks = LookupTable.new
39 @internal.key?(key) || @alias.key?(key)
43 @internal.keys + @alias.keys
52 @internal[@alias[key]]
57 if !@internal.key?(key) && alias_key = @alias[key] then
58 @internal[alias_key] = data
59 elsif @hooks.key? key then
60 @hooks[key][1].call(data)
66 def add_alias(from, to)
67 if hook = @hooks[from]
69 elsif alias_key = @alias[from] then
70 @alias[to] = alias_key
77 raise RuntimeError, "unable to set global"
80 def set_hook(var, getter, setter)
81 unless getter.respond_to?(:call)
82 raise ArgumentError, "getter must respond to call"
86 setter = method(:illegal_set)
87 elsif setter.respond_to?(:call)
88 raise ArgumentError, "setter must respond to call"
91 @hooks[var] = [getter, setter]
95 Globals = GlobalVariables.new