Class: RIO::Cx::Vars
- Extended by:
- Forwardable
- Defined in:
- lib/rio/context.rb
Constant Summary collapse
- BEQUEATH_KEYS =
%w[chomp strip rename closeoneof closeoncopy]
Instance Method Summary collapse
- #[]=(key, val) ⇒ Object
-
#bequeath(oldcx) ⇒ Object
BEQUEATH_KEYS = %w[chomp strip rename].
- #delete(key) ⇒ Object
- #get_keystate(key) ⇒ Object
-
#initialize(h = Hash.new, exp = Hash.new) ⇒ Vars
constructor
A new instance of Vars.
- #initialize_copy(*args) ⇒ Object
- #inspect ⇒ Object
- #set_(key, val) ⇒ Object
- #set_keystate(key, key_exists, key_val, key_explicit) ⇒ Object
Constructor Details
#initialize(h = Hash.new, exp = Hash.new) ⇒ Vars
Returns a new instance of Vars.
40 41 42 43 |
# File 'lib/rio/context.rb', line 40 def initialize(h=Hash.new,exp=Hash.new) @values = h @explicit = exp end |
Instance Method Details
#[]=(key, val) ⇒ Object
82 83 84 85 |
# File 'lib/rio/context.rb', line 82 def []=(key,val) @values[key] = val @explicit[key] = true end |
#bequeath(oldcx) ⇒ Object
BEQUEATH_KEYS = %w[chomp strip rename]
51 52 53 54 55 56 57 58 59 |
# File 'lib/rio/context.rb', line 51 def bequeath(oldcx) keys = BEQUEATH_KEYS ncx = oldcx.clone #ncx = Vars.new keys.each { |key| ncx.set_(key,@values[key]) if @values.has_key?(key) } ncx end |
#delete(key) ⇒ Object
60 61 62 63 |
# File 'lib/rio/context.rb', line 60 def delete(key) @values.delete(key) @explicit.delete(key) end |
#get_keystate(key) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/rio/context.rb', line 64 def get_keystate(key) key_exists = @values.key?(key) key_val = @values[key] key_explicit = @explicit[key] [key,key_exists,key_val,key_explicit] end |
#initialize_copy(*args) ⇒ Object
44 45 46 47 48 |
# File 'lib/rio/context.rb', line 44 def initialize_copy(*args) super @values = @values.clone @explicit = @explicit.clone end |
#inspect ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rio/context.rb', line 86 def inspect() str = sprintf('#<Cx:0x%08x ',self.object_id) vary = {} @values.each { |k,v| name = k name += '_' unless @explicit[k] if v == true vary[name] = nil elsif v == false vary[name] = 'false' else vary[name] = v end } strs = [] vary.each { |k,v| if v.nil? strs << k else strs << "#{k}(#{v.inspect})" end } str += strs.join(',') str +='>' str end |
#set_(key, val) ⇒ Object
79 80 81 |
# File 'lib/rio/context.rb', line 79 def set_(key,val) @values[key] = val unless @explicit[key] end |
#set_keystate(key, key_exists, key_val, key_explicit) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/rio/context.rb', line 70 def set_keystate(key,key_exists,key_val,key_explicit) if(key_exists) then @values[key] = key_val @explicit[key] = key_explicit else @values.delete(key) @explicit.delete(key) end end |