Class: FunctionChain::BaseChain

Inherits:
Object
  • Object
show all
Defined in:
lib/function_chain/base_chain.rb

Overview

Base class of PullChain, RelayChain

Direct Known Subclasses

PullChain, RelayChain

Instance Method Summary collapse

Instance Method Details

#add(function) ⇒ Object

Add function to chain



11
12
13
# File 'lib/function_chain/base_chain.rb', line 11

def add(function)
  insert(chain_elements.size, function)
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

#clearObject

Clear function chain



38
39
40
# File 'lib/function_chain/base_chain.rb', line 38

def clear
  chain_elements.clear
end

#delete_at(index) ⇒ Object

Delete from chain



32
33
34
35
# File 'lib/function_chain/base_chain.rb', line 32

def delete_at(index)
  chain_elements.delete_at(index)
  self
end

#insert(index, function) ⇒ Object

Insert function to chain



22
23
24
25
26
27
28
29
# File 'lib/function_chain/base_chain.rb', line 22

def insert(index, function)
  if function.is_a? String
    do_insert_by_string(index, function)
  else
    do_insert(index, function)
  end
  self
end

#insert_all(index, *functions) ⇒ Object

Insert functions to chain



16
17
18
19
# File 'lib/function_chain/base_chain.rb', line 16

def insert_all(index, *functions)
  functions.each_with_index { |f, i| insert(index + i, f) }
  self
end

#to_sObject



42
43
44
# File 'lib/function_chain/base_chain.rb', line 42

def to_s
  "#{self.class}#{chain_elements.map(&:to_s)}"
end