Class: Fairy::PoolDictionary
- Inherits:
-
Object
- Object
- Fairy::PoolDictionary
- Defined in:
- lib/fairy/share/pool-dictionary.rb
Instance Attribute Summary collapse
-
#pool_cv ⇒ Object
readonly
Returns the value of attribute pool_cv.
-
#pool_mutex ⇒ Object
readonly
Returns the value of attribute pool_mutex.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #def_variable(vname, value = nil) ⇒ Object
-
#initialize ⇒ PoolDictionary
constructor
A new instance of PoolDictionary.
Constructor Details
#initialize ⇒ PoolDictionary
Returns a new instance of PoolDictionary.
9 10 11 12 13 |
# File 'lib/fairy/share/pool-dictionary.rb', line 9 def initialize @pool = {} @pool_mutex = Mutex.new @pool_cv = ConditionVariable.new end |
Instance Attribute Details
#pool_cv ⇒ Object (readonly)
Returns the value of attribute pool_cv.
16 17 18 |
# File 'lib/fairy/share/pool-dictionary.rb', line 16 def pool_cv @pool_cv end |
#pool_mutex ⇒ Object (readonly)
Returns the value of attribute pool_mutex.
15 16 17 |
# File 'lib/fairy/share/pool-dictionary.rb', line 15 def pool_mutex @pool_mutex end |
Instance Method Details
#[](name) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/fairy/share/pool-dictionary.rb', line 34 def [](name) @pool_mutex.synchronize do ERR::Raise NoAssignedVarriable, name unless @pool.key?(name) @pool[name] end end |
#[]=(name, value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fairy/share/pool-dictionary.rb', line 41 def []=(name, value) @pool_mutex.synchronize do ERR::Raise NoAssignedVarriable, name unless @pool.key?(name) case value when DeepConnect::Reference @pool[name] = value.dc_deep_copy else @pool[name] = value end end end |
#def_variable(vname, value = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fairy/share/pool-dictionary.rb', line 18 def def_variable(vname, value = nil) @pool_mutex.synchronize do if @pool.key?(vname) ERR::Raise ERR::AlreadyAssignedVarriable, vname end case value when DeepConnect::Reference @pool[vname] = value.dc_deep_copy else @pool[vname] = value end instance_eval "def #{vname}; self[:#{vname}]; end" instance_eval "def #{vname}=(v); self[:#{vname}]=v; end" end end |