Class: WebConsole::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/web_console/evaluator.rb

Overview

Simple Ruby code evaluator.

This class wraps a Binding object and evaluates code inside of it. The difference of a regular Binding eval is that Evaluator will always return a string and will format exception output.

Constant Summary collapse

@@cleaner =
ActiveSupport::BacktraceCleaner.new

Instance Method Summary collapse

Constructor Details

#initialize(binding = TOPLEVEL_BINDING) ⇒ Evaluator

Returns a new instance of Evaluator.



13
14
15
# File 'lib/web_console/evaluator.rb', line 13

def initialize(binding = TOPLEVEL_BINDING)
  @binding = binding
end

Instance Method Details

#eval(input) ⇒ Object



17
18
19
20
21
# File 'lib/web_console/evaluator.rb', line 17

def eval(input)
  "=> #{@binding.eval(input).inspect}\n"
rescue Exception => exc
  format_exception(exc)
end