Class: ProcBuffer
- Inherits:
-
Object
- Object
- ProcBuffer
- Includes:
- Enumerable
- Defined in:
- lib/proc_buffer.rb,
lib/proc_buffer/version.rb
Overview
TODO: Documentation ProcBuffer
Constant Summary collapse
- VERSION =
'0.1.0'.freeze
Instance Method Summary collapse
- #actions ⇒ Object
- #append(&block) ⇒ Object (also: #push)
- #each ⇒ Object
-
#initialize(*actions) ⇒ ProcBuffer
constructor
A new instance of ProcBuffer.
- #pop(n = nil) ⇒ Object
- #reverse_run ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(*actions) ⇒ ProcBuffer
Returns a new instance of ProcBuffer.
8 9 10 11 |
# File 'lib/proc_buffer.rb', line 8 def initialize(*actions) # For now we will not handle actions that do not respond to #call @actions = actions.select { |action| action.respond_to?(:call) } end |
Instance Method Details
#actions ⇒ Object
13 14 15 |
# File 'lib/proc_buffer.rb', line 13 def actions @actions.dup end |
#append(&block) ⇒ Object Also known as: push
29 30 31 |
# File 'lib/proc_buffer.rb', line 29 def append(&block) @actions << block end |
#each ⇒ Object
17 18 19 |
# File 'lib/proc_buffer.rb', line 17 def each @actions.each { |action| yield action } end |
#pop(n = nil) ⇒ Object
35 36 37 38 |
# File 'lib/proc_buffer.rb', line 35 def pop(n = nil) return @actions.pop.call unless n (1..n).map { @actions.pop.call } end |
#reverse_run ⇒ Object
25 26 27 |
# File 'lib/proc_buffer.rb', line 25 def reverse_run @actions.reverse.map { |action| call(action) } end |
#run ⇒ Object
21 22 23 |
# File 'lib/proc_buffer.rb', line 21 def run map(&:call) end |