Class: Woyo::Attributes::AttributesHash
- Defined in:
- lib/woyo/world/attributes.rb
Instance Attribute Summary collapse
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
Instance Method Summary collapse
- #[]=(attr, value) ⇒ Object
- #add_listener(attr, listener) ⇒ Object
-
#initialize ⇒ AttributesHash
constructor
A new instance of AttributesHash.
- #set ⇒ Object
Constructor Details
#initialize ⇒ AttributesHash
Returns a new instance of AttributesHash.
18 19 20 |
# File 'lib/woyo/world/attributes.rb', line 18 def initialize @listeners = {} end |
Instance Attribute Details
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
16 17 18 |
# File 'lib/woyo/world/attributes.rb', line 16 def listeners @listeners end |
Instance Method Details
#[]=(attr, value) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/woyo/world/attributes.rb', line 27 def []= attr, value old_value = self[attr] super if value != old_value @listeners[attr].each { |listener| listener.notify attr, value } if @listeners[attr] # attribute listeners (groups, etc..) @listeners[:*].each { |listener| listener.notify attr, value } if @listeners[:*] # wildcard listeners (trackers) end end |
#add_listener(attr, listener) ⇒ Object
22 23 24 25 |
# File 'lib/woyo/world/attributes.rb', line 22 def add_listener attr, listener @listeners[attr] ||= [] @listeners[attr] << listener end |
#set ⇒ Object
14 |
# File 'lib/woyo/world/attributes.rb', line 14 alias_method :set, :[]= |