Class: Rack::Webconsole::Sandbox

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/webconsole/sandbox.rb

Overview

A sandbox to evaluate Ruby in. It is responsible for retrieving local variables stored in `@locals`, and resetting the environment.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Catches all the undefined local variables and tries to retrieve them from `@locals`. If it doesn't find them, it falls back to the default method missing behavior.



11
12
13
14
# File 'lib/rack/webconsole/sandbox.rb', line 11

def method_missing(method, *args, &block)
  @locals ||= {}
  @locals[method] || super(method, *args, &block)
end

Instance Method Details

#reload!String

Makes the console use a fresh, new Rack::Webconsole::Sandbox with all local variables resetted.



20
21
22
23
# File 'lib/rack/webconsole/sandbox.rb', line 20

def reload!
  $sandbox = Sandbox.new
  'ok'
end