class GlobalsBase
This class is for storing global variables. This is accomplished by inheriting the singleton class. To use a global variable it must be registered and then if some part of the program needs to be notified of a change a notifier can be registered for that variable.
Public Class Methods
new()
click to toggle source
# File libs/zabcon_globals.rb, line 70 def initialize @hash={} @callbacks={} end
Public Instance Methods
[](key)
click to toggle source
overload the array operator
# File libs/zabcon_globals.rb, line 96 def [](key) debug(9,:var=>key,:msg=>"Entering [] (key)",:overload=>true) if @hash[key].nil? return nil else return @hash[key] end end
[]=(key,val)
click to toggle source
overload the assignment operator
# File libs/zabcon_globals.rb, line 76 def []=(key,val) debug(9,:var=>[key,val],:msg=>"Entering []= (key,val)",:overload=>true) if val.nil? delete(key) if !@hash[key].nil? else if !@hash[key].nil? and (@hash[key].class==Fixnum or @hash[key].class==Bignum) @hash[key]=Integer(val) else @hash[key]=val end if !@callbacks[key].nil? @callbacks[key].each {|proc| proc.call(@hash[key]) #use the value stored in the hash should there have been a conversion } end end end
delete(key)
click to toggle source
# File libs/zabcon_globals.rb, line 109 def delete(key) @hash.delete(key) end
each() { |k,v| ... }
click to toggle source
# File libs/zabcon_globals.rb, line 117 def each @hash.each {|k,v| yield k,v } end
empty?()
click to toggle source
# File libs/zabcon_globals.rb, line 113 def empty? return @hash.empty? end
register_notifier(key,proc)
click to toggle source
Register a function to be called when the value of key changes.
# File libs/zabcon_globals.rb, line 122 def register_notifier(key,proc) debug(9,:var=>[key,proc],:msg=>"Entering register_notifier (key,proc)") if @callbacks[key].nil? @callbacks[key]=[proc] else @callbacks[key]<<proc end end
select_keys(keys)
click to toggle source
# File libs/zabcon_globals.rb, line 105 def select_keys(keys) @hash.select_keys(keys) end