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.
10 11 12 13 14 |
# File 'lib/fairy/share/pool-dictionary.rb', line 10 def initialize @pool = {} @pool_mutex = Mutex.new @pool_cv = XThread::ConditionVariable.new end |
Instance Attribute Details
#pool_cv ⇒ Object (readonly)
Returns the value of attribute pool_cv.
17 18 19 |
# File 'lib/fairy/share/pool-dictionary.rb', line 17 def pool_cv @pool_cv end |
#pool_mutex ⇒ Object (readonly)
Returns the value of attribute pool_mutex.
16 17 18 |
# File 'lib/fairy/share/pool-dictionary.rb', line 16 def pool_mutex @pool_mutex end |
Instance Method Details
#[](name) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/fairy/share/pool-dictionary.rb', line 35 def [](name) @pool_mutex.synchronize do ERR::Raise NoAssignedVarriable, name unless @pool.key?(name) @pool[name] end end |
#[]=(name, value) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fairy/share/pool-dictionary.rb', line 42 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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fairy/share/pool-dictionary.rb', line 19 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 |