Class: IRuby::PryBackend

Inherits:
Object
  • Object
show all
Includes:
History
Defined in:
lib/iruby/backend.rb

Instance Method Summary collapse

Constructor Details

#initializePryBackend

Returns a new instance of PryBackend.



55
56
57
58
59
60
61
# File 'lib/iruby/backend.rb', line 55

def initialize
  require 'pry'
  Pry.pager = false # Don't use the pager
  Pry.print = proc {|output, value|} # No result printing
  Pry.exception_handler = proc {|output, exception, _| }
  reset
end

Instance Method Details

#complete(code) ⇒ Object



79
80
81
# File 'lib/iruby/backend.rb', line 79

def complete(code)
  @pry.complete(code)
end

#eval(code, store_history) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/iruby/backend.rb', line 63

def eval(code, store_history)
  @pry.last_result = nil
  unless @pry.eval(code)
    reset
    raise SystemExit
  end
  unless @pry.eval_string.empty?
    syntax_error = @pry.eval_string
    @pry.reset_eval_string
    @pry.evaluate_ruby syntax_error
  end
  raise @pry.last_exception if @pry.last_result_is_exception?
  @pry.push_initial_binding unless @pry.current_binding # ensure that we have a binding
  @pry.last_result
end

#resetObject



83
84
85
# File 'lib/iruby/backend.rb', line 83

def reset
  @pry = Pry.new(output: $stdout, target: TOPLEVEL_BINDING)
end