Class: FunctionChain::BaseChain
- Inherits:
-
Object
- Object
- FunctionChain::BaseChain
- Defined in:
- lib/function_chain/base_chain.rb
Overview
Base class of PullChain, RelayChain
Direct Known Subclasses
Instance Method Summary collapse
-
#add(function = nil, &block) ⇒ Object
Add function to chain.
-
#add_all(*functions) ⇒ Object
Add functions to chain.
-
#clear ⇒ Object
Clear function chain.
-
#delete_at(index) ⇒ Object
Delete from chain.
-
#insert(index, function = nil, &block) ⇒ Object
Insert function to chain.
-
#insert_all(index, *functions) ⇒ Object
Insert functions to chain.
- #to_s ⇒ Object
Instance Method Details
#add(function = nil, &block) ⇒ Object
Add function to chain
Example: add(value) or add { your code }
13 14 15 |
# File 'lib/function_chain/base_chain.rb', line 13 def add(function = nil, &block) insert(chain_elements.size, function, &block) end |
#add_all(*functions) ⇒ Object
Add functions to chain
5 6 7 8 |
# File 'lib/function_chain/base_chain.rb', line 5 def add_all(*functions) insert_all(chain_elements.size, *functions) self end |
#clear ⇒ Object
Clear function chain
43 44 45 46 |
# File 'lib/function_chain/base_chain.rb', line 43 def clear chain_elements.clear self end |
#delete_at(index) ⇒ Object
Delete from chain
37 38 39 40 |
# File 'lib/function_chain/base_chain.rb', line 37 def delete_at(index) chain_elements.delete_at(index) self end |
#insert(index, function = nil, &block) ⇒ Object
Insert function to chain
Example: insert(i, value) or insert(i) { your code }
26 27 28 29 30 31 32 33 34 |
# File 'lib/function_chain/base_chain.rb', line 26 def insert(index, function = nil, &block) validate_exclusive_value(function, block) case function when String then do_insert_by_string(index, function) when NilClass then do_insert(index, block) else do_insert(index, function) end self end |
#insert_all(index, *functions) ⇒ Object
Insert functions to chain
18 19 20 21 |
# File 'lib/function_chain/base_chain.rb', line 18 def insert_all(index, *functions) functions.each_with_index { |f, i| insert(index + i, f) } self end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/function_chain/base_chain.rb', line 48 def to_s "#{self.class}#{chain_elements.map(&:to_s)}" end |