Class: Sevgi::Executor
- Inherits:
-
Object
show all
- Includes:
- Singleton
- Defined in:
- lib/sevgi/executor.rb,
lib/sevgi/executor/error.rb,
lib/sevgi/executor/scope.rb,
lib/sevgi/executor/source.rb
Defined Under Namespace
Classes: Error, Scope, Source
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Executor.
42
|
# File 'lib/sevgi/executor.rb', line 42
def initialize = @scopes = []
|
Class Method Details
.execute(string, file: nil, line: nil, require: nil, receiver: nil, &block) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/sevgi/executor.rb', line 19
def self.execute(string, file: nil, line: nil, require: nil, receiver: nil, &block)
return if string.empty?
Signal.trap("INT") { Kernel.abort("") }
::Kernel.require(require) if require
catch(:result) do
instance.create.call(Source.new(string:, file:, line:), receiver, &block)
end
ensure
instance.shutdown
end
|
.execute_file(file, require: nil, receiver: nil, &block) ⇒ Object
34
35
36
|
# File 'lib/sevgi/executor.rb', line 34
def self.execute_file(file, require: nil, receiver: nil, &block)
execute(::File.read(file), file: file, line: 1, require:, receiver:, &block)
end
|
.load(file) ⇒ Object
13
14
15
16
17
|
# File 'lib/sevgi/executor.rb', line 13
def self.load(file, ...)
PanicError.("box stack empty; create a box first") unless instance.current
instance.current.load(file, ...)
end
|
.shutdown ⇒ Object
38
39
40
|
# File 'lib/sevgi/executor.rb', line 38
def self.shutdown
instance.shutdown
end
|
Instance Method Details
#create(scope = nil) ⇒ Object
44
|
# File 'lib/sevgi/executor.rb', line 44
def create(scope = nil) = Scope.new(scope).tap { @scopes << it }
|
#current ⇒ Object
46
|
# File 'lib/sevgi/executor.rb', line 46
def current = @scopes.last
|
#shutdown ⇒ Object
48
|
# File 'lib/sevgi/executor.rb', line 48
def shutdown = @scopes.pop
|