Class: Fir::Evaluater

Inherits:
Object
  • Object
show all
Includes:
ScreenHelper
Defined in:
lib/fir/evaluater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ScreenHelper

#clear, #cursor_back, #horizontal_absolute, #line_prompt, #next_line, #previous_line

Constructor Details

#initialize(output, error) ⇒ Evaluater

Returns a new instance of Evaluater.



13
14
15
16
# File 'lib/fir/evaluater.rb', line 13

def initialize(output, error)
  @output = output
  @error = error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



11
12
13
# File 'lib/fir/evaluater.rb', line 11

def error
  @error
end

#outputObject (readonly)

Returns the value of attribute output.



10
11
12
# File 'lib/fir/evaluater.rb', line 10

def output
  @output
end

Instance Method Details

#perform(state) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fir/evaluater.rb', line 18

def perform(state)
  return unless state.executable?
  begin
    write_result(eval(state.lines.join("\n"), state.repl_binding, 'fir'))
  rescue Exception => e
    write_error(e)
  ensure
    output.syswrite(line_prompt)
  end
end