Class: Sevgi::Sandbox::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/sevgi/internal/sandbox.rb

Instance Method Summary collapse

Constructor Details

#initializeBox

Returns a new instance of Box.



26
27
28
29
# File 'lib/sevgi/internal/sandbox.rb', line 26

def initialize
  @module = Module.new
  @loaded = {}
end

Instance Method Details

#load(file, receiver = Undefined, &preblock) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/sevgi/internal/sandbox.rb', line 31

def load(file, receiver = Undefined, &preblock)
  return if @loaded[file = F.existing!(file, extensions: [ EXTENSION ])]

  Undefined.default(receiver, TOPLEVEL_BINDING.receiver).instance_exec(&preblock) if preblock

  ::Kernel.load(file, @module) and (@loaded[file] = true)
rescue Exception => e # rubocop:disable Lint/RescueException
  warn(description(e, file))
  raise(e)
end