Class: Functional::TopDown

Inherits:
Base show all
Defined in:
lib/functional.rb

Instance Attribute Summary

Attributes inherited from Base

#exe, #next

Instance Method Summary collapse

Methods inherited from Base

#to_proc

Constructor Details

#initialize(start, *a, &e) ⇒ TopDown

Returns a new instance of TopDown.



99
100
101
102
# File 'lib/functional.rb', line 99

def initialize start, *a, &e
  @next.call *a, &e
  @buffer, @start = nil, start
end

Instance Method Details

#call(a) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/functional.rb', line 104

def call a
  if @exe.call a
    @next.call @buffer
    @buffer = @start.dup+a
  else
    @buffer += a
  end
end

#endObject



113
114
115
116
# File 'lib/functional.rb', line 113

def end
  @next.call @buffer
  @next.end
end