Class: Johnson::Runtime
- Inherits:
-
Object
- Object
- Johnson::Runtime
- Defined in:
- lib/johnson/runtime.rb
Instance Attribute Summary collapse
-
#delegate ⇒ Object
readonly
Returns the value of attribute delegate.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#break(filename, linenum, &block) ⇒ Object
Yield to
block
infilename
atlinenum
. -
#compile(script, filename = nil, linenum = nil) ⇒ Object
Compile
script
withfilename
andlinenum
. - #evaluate(expression, filename = nil, linenum = nil) ⇒ Object
- #evaluate_compiled_script(script) ⇒ Object
- #global ⇒ Object
-
#initialize(delegate = Johnson::SpiderMonkey::Runtime) ⇒ Runtime
constructor
A new instance of Runtime.
- #load(*files) ⇒ Object
-
#require(*files) ⇒ Object
Johnson.require on each file in
files
.
Constructor Details
#initialize(delegate = Johnson::SpiderMonkey::Runtime) ⇒ Runtime
Returns a new instance of Runtime.
5 6 7 8 9 |
# File 'lib/johnson/runtime.rb', line 5 def initialize(delegate=Johnson::SpiderMonkey::Runtime) @delegate = delegate.is_a?(Class) ? delegate.new : delegate evaluate(Johnson::PRELUDE, "Johnson::PRELUDE", 1) global.Johnson.runtime = self end |
Instance Attribute Details
#delegate ⇒ Object (readonly)
Returns the value of attribute delegate.
3 4 5 |
# File 'lib/johnson/runtime.rb', line 3 def delegate @delegate end |
Instance Method Details
#[](key) ⇒ Object
11 12 13 |
# File 'lib/johnson/runtime.rb', line 11 def [](key) delegate[key.to_s] end |
#[]=(key, value) ⇒ Object
15 16 17 |
# File 'lib/johnson/runtime.rb', line 15 def []=(key, value) delegate[key.to_s] = value end |
#break(filename, linenum, &block) ⇒ Object
Yield to block
in filename
at linenum
48 49 50 |
# File 'lib/johnson/runtime.rb', line 48 def break(filename, linenum, &block) delegate.break(filename, linenum, &block) end |
#compile(script, filename = nil, linenum = nil) ⇒ Object
Compile script
with filename
and linenum
42 43 44 |
# File 'lib/johnson/runtime.rb', line 42 def compile(script, filename=nil, linenum=nil) delegate.compile(script, filename, linenum) end |
#evaluate(expression, filename = nil, linenum = nil) ⇒ Object
19 20 21 22 |
# File 'lib/johnson/runtime.rb', line 19 def evaluate(expression, filename=nil, linenum=nil) return nil if expression.nil? delegate.evaluate(expression, filename, linenum) end |
#evaluate_compiled_script(script) ⇒ Object
52 53 54 |
# File 'lib/johnson/runtime.rb', line 52 def evaluate_compiled_script(script) delegate.evaluate_compiled(script) end |
#global ⇒ Object
24 25 26 |
# File 'lib/johnson/runtime.rb', line 24 def global delegate.global end |
#load(*files) ⇒ Object
28 29 30 |
# File 'lib/johnson/runtime.rb', line 28 def load(*files) files.map { |f| delegate.evaluate(File.read(f).gsub(/\A#!.*$/, ''), f, 1) }.last end |
#require(*files) ⇒ Object
Johnson.require on each file in files
34 35 36 37 38 |
# File 'lib/johnson/runtime.rb', line 34 def require(*files) files.each do |file| evaluate("Johnson.require('#{file}');") end end |