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.to_sym] || 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.

Returns:

  • (String)

    ‘ok’ to make the user notice.



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

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

#requestRack::Request

Returns the current page request object for inspection purposes.

Returns:

  • (Rack::Request)

    the current page request object.



28
29
30
# File 'lib/rack/webconsole/sandbox.rb', line 28

def request
  Webconsole::Repl.request
end