Class: Foobara::Callback::Set
- Inherits:
-
Object
- Object
- Foobara::Callback::Set
- Defined in:
- foobara-0.5.8/projects/typesystem/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.
- #size ⇒ Object
- #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 'projects/typesystem/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 'projects/typesystem/projects/callback/src/set.rb', line 4 def callbacks @callbacks end |
Instance Method Details
#[](type) ⇒ Object
35 36 37 |
# File 'projects/typesystem/projects/callback/src/set.rb', line 35 def [](type) send(type) end |
#size ⇒ Object
14 15 16 |
# File 'projects/typesystem/projects/callback/src/set.rb', line 14 def size callbacks.size end |
#union(set) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'projects/typesystem/projects/callback/src/set.rb', line 18 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
31 32 33 |
# File 'projects/typesystem/projects/callback/src/set.rb', line 31 def |(other) union(other) end |