Module: InstanceStorage::InstanceStorageExtend
- Defined in:
- lib/instance_storage.rb
Instance Method Summary collapse
-
#[](name) ⇒ Object
インスタンス event_name を返す。既に有る場合はそのインスタンス、ない場合は新しく作って返す。 ==== Args [name] インスタンスの名前(Symbol) ==== Return Event.
-
#clear! ⇒ Object
定義されているインスタンスを全て削除する.
- #destroy(name) ⇒ Object
-
#instance(name) ⇒ Object
name に対応するインスタンスが既にあれば真 ==== Args [name] インスタンスの名前(Symbol) ==== Return インスタンスかnil.
-
#instance_exist?(name) ⇒ Boolean
名前 name に対応するインスタンスが存在するか否かを返す ==== Args [name] インスタンスの名前(Symbol) ==== Return インスタンスが存在するなら真.
-
#instances ⇒ Object
このクラスのインスタンスを全て返す ==== Return インスタンスの配列(Array).
- #instances_dict ⇒ Object
-
#instances_name ⇒ Object
このクラスのインスタンスの名前を全て返す ==== Return インスタンスの名前の配列(Array).
- #storage_lock ⇒ Object
Instance Method Details
#[](name) ⇒ Object
インスタンス event_name を返す。既に有る場合はそのインスタンス、ない場合は新しく作って返す。
Args
- name
-
インスタンスの名前(Symbol)
Return
Event
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/instance_storage.rb', line 47 def [](name) name_sym = name.to_sym if instances_dict.has_key?(name_sym) instances_dict[name_sym] else storage_lock.synchronize{ if instances_dict.has_key?(name_sym) instances_dict[name_sym] else instances_dict[name_sym] = self.new(name_sym) end } end end |
#clear! ⇒ Object
定義されているインスタンスを全て削除する
37 38 39 40 |
# File 'lib/instance_storage.rb', line 37 def clear! @instances = nil self end |
#destroy(name) ⇒ Object
86 87 88 89 |
# File 'lib/instance_storage.rb', line 86 def destroy(name) instances_dict.delete(name.to_sym) self end |
#instance(name) ⇒ Object
name に対応するインスタンスが既にあれば真
Args
- name
-
インスタンスの名前(Symbol)
Return
インスタンスかnil
83 84 |
# File 'lib/instance_storage.rb', line 83 def instance(name) instances_dict[name.to_sym] end |
#instance_exist?(name) ⇒ Boolean
名前 name に対応するインスタンスが存在するか否かを返す
Args
- name
-
インスタンスの名前(Symbol)
Return
インスタンスが存在するなら真
75 76 |
# File 'lib/instance_storage.rb', line 75 def instance_exist?(name) instances_dict.has_key? name.to_sym end |
#instances ⇒ Object
このクラスのインスタンスを全て返す
Return
インスタンスの配列(Array)
61 62 |
# File 'lib/instance_storage.rb', line 61 def instances instances_dict.values end |
#instances_dict ⇒ Object
30 31 |
# File 'lib/instance_storage.rb', line 30 def instances_dict @instances ||= {} end |
#instances_name ⇒ Object
このクラスのインスタンスの名前を全て返す
Return
インスタンスの名前の配列(Array)
67 68 |
# File 'lib/instance_storage.rb', line 67 def instances_name instances_dict.keys end |
#storage_lock ⇒ Object
33 34 |
# File 'lib/instance_storage.rb', line 33 def storage_lock @storage_lock ||= Mutex.new end |