Class: Safemode::Box

Inherits:
Object show all
Defined in:
lib/safemode.rb

Instance Method Summary collapse

Constructor Details

#initialize(delegate = nil, delegate_methods = [], filename = nil, line = nil) ⇒ Box

Returns a new instance of Box.



42
43
44
45
46
# File 'lib/safemode.rb', line 42

def initialize(delegate = nil, delegate_methods = [], filename = nil, line = nil)
  @scope = Scope.new(delegate, delegate_methods)
  @filename = filename
  @line = line
end

Instance Method Details

#eval(code, assigns = {}, locals = {}, &block) ⇒ Object



48
49
50
51
52
# File 'lib/safemode.rb', line 48

def eval(code, assigns = {}, locals = {}, &block)
  code = Parser.jail(code)
  binding = @scope.bind(assigns, locals, &block)
  result = Kernel.eval(code, binding, @filename || __FILE__, @line || __LINE__)
end

#outputObject



54
55
56
# File 'lib/safemode.rb', line 54

def output
  @scope.output
end