Class: Foobara::Callback::Set
- Inherits:
-
Object
- Object
- Foobara::Callback::Set
- Defined in:
- foobara-0.0.110/projects/callback/src/set.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
Instance Method Summary collapse
- #[](type) ⇒ Object
-
#initialize(callback_hash = {}) ⇒ Set
constructor
A new instance of Set.
- #union(set) ⇒ Object
- #|(other) ⇒ Object
Constructor Details
#initialize(callback_hash = {}) ⇒ Set
Returns a new instance of Set.
6 7 8 9 10 11 12 |
# File 'foobara-0.0.110/projects/callback/src/set.rb', line 6 def initialize(callback_hash = {}) self.callbacks = {} callback_hash.each do |type, blocks| send("#{type}=", blocks.dup) end end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
4 5 6 |
# File 'foobara-0.0.110/projects/callback/src/set.rb', line 4 def callbacks @callbacks end |
Instance Method Details
#[](type) ⇒ Object
33 34 35 |
# File 'foobara-0.0.110/projects/callback/src/set.rb', line 33 def [](type) send(type) end |
#union(set) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'foobara-0.0.110/projects/callback/src/set.rb', line 16 def union(set) unioned = Set.new(callbacks) set.callbacks.each_pair do |type, blocks| next if blocks.empty? unioned_blocks = unioned[type] blocks.each { |block| unioned_blocks << block } end unioned end |
#|(other) ⇒ Object
29 30 31 |
# File 'foobara-0.0.110/projects/callback/src/set.rb', line 29 def |(other) union(other) end |