Module: Printrun::Core

Included in:
Printrun
Defined in:
lib/printrun/core.rb

Instance Method Summary collapse

Instance Method Details

#line_eval(world, line2ansp) {|block| ... } ⇒ Object

Parameters:

  • world (Binding)

    Binding to use for evaluation of statements

  • line2ansp (Proc)

    Proc that takes the line to process as parameter and returns a Proc taking the result of previous line’s evaluation as parameter

Yields:

  • (block)

    Block of code to process (line-eval~~~).



20
21
22
# File 'lib/printrun/core.rb', line 20

def line_eval(world, line2ansp, &block)
  lines(block.to_source).each { |line| line2ansp[line][eval(line, world)] }
end

#lines(source) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/printrun/core.rb', line 7

def lines(source)
  Enumerator.new do |out|
    source.split("\n")[1..-2].reduce("") do |buffer, line|
      buffer << "\n#{line}"
      Ripper.sexp_raw(buffer) ? (out << buffer) && "" : buffer
    end
  end
end