# class WebConsole::Evaluator

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.

### Public Class Methods

new(binding = TOPLEVEL_BINDING) click to toggle source

    # File lib/web_console/evaluator.rb, line 13
    def initialize(binding = TOPLEVEL_BINDING)
      @binding = binding
    end

### Public Instance Methods

eval(input) click to toggle source

    # File lib/web_console/evaluator.rb, line 17
    def eval(input)
      "=> #{@binding.eval(input).inspect}\n"
    rescue Exception => exc
      format_exception(exc)
    end

### Private Instance Methods

format_exception(exc) click to toggle source

    # File lib/web_console/evaluator.rb, line 25
    def format_exception(exc)
      backtrace = cleaner.clean(Array(exc.backtrace) - caller)

      format = "#{exc.class.name}: #{exc}\n"
      format << backtrace.map { |trace| "\tfrom #{trace}\n" }.join
      format
    end