class WebConsole::Evaluator
return a string and will format exception output.
difference of a regular Binding
eval is that Evaluator
will always
This class wraps a Binding
object and evaluates code inside of it. The
Simple Ruby code evaluator.
def eval(input)
def eval(input) # Binding#source_location is available since Ruby 2.6. if @binding.respond_to? :source_location "=> #{@binding.eval(input, *@binding.source_location).inspect}\n" else "=> #{@binding.eval(input).inspect}\n" end rescue Exception => exc format_exception(exc) end
def format_exception(exc)
def format_exception(exc) backtrace = cleaner.clean(Array(exc.backtrace) - caller) format = "#{exc.class.name}: #{exc}\n".dup format << backtrace.map { |trace| "\tfrom #{trace}\n" }.join format end
def initialize(binding = TOPLEVEL_BINDING)
def initialize(binding = TOPLEVEL_BINDING) @binding = binding end