Class: Rack::Webconsole::Sandbox
- Inherits:
-
Object
- Object
- Rack::Webconsole::Sandbox
- 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
-
#method_missing(method, *args, &block) ⇒ Object
Catches all the undefined local variables and tries to retrieve them from ‘@locals`.
-
#reload! ⇒ String
Makes the console use a fresh, new Sandbox with all local variables resetted.
-
#request ⇒ Rack::Request
Returns the current page request object for inspection purposes.
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.
20 21 22 23 |
# File 'lib/rack/webconsole/sandbox.rb', line 20 def reload! $sandbox = Sandbox.new 'ok' end |
#request ⇒ Rack::Request
Returns the current page request object for inspection purposes.
28 29 30 |
# File 'lib/rack/webconsole/sandbox.rb', line 28 def request Webconsole::Repl.request end |