Class: RubyOnRuby::Context
- Inherits:
-
Object
- Object
- RubyOnRuby::Context
- Defined in:
- lib/ruby_on_ruby/context.rb
Instance Attribute Summary collapse
-
#v8_context ⇒ Object
Returns the value of attribute v8_context.
Instance Method Summary collapse
- #eval(str) ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #js_eval(str) ⇒ Object
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ruby_on_ruby/context.rb', line 10 def initialize self.v8_context = V8::Context.new v8_context['console'] = Console.new # Mock out `console`. FileLoader.setup(v8_context) # Mock out XMLHttpRequest to allow loading of Ruby Standard Library files. v8_context.load(File.("../../../vendor/javascripts/emscripted-ruby/ruby.closure.js", __FILE__)) # Load Ruby itself. @input = RubyStream.new(STDIN) @output = RubyStream.new(STDOUT) @error = RubyStream.new(STDERR) v8_context['input'] = @input.input v8_context['output'] = @output.output v8_context['error'] = @error.output v8_context.eval "Ruby.initialize(input, output, error)" end |
Instance Attribute Details
#v8_context ⇒ Object
Returns the value of attribute v8_context.
8 9 10 |
# File 'lib/ruby_on_ruby/context.rb', line 8 def v8_context @v8_context end |
Instance Method Details
#eval(str) ⇒ Object
24 25 26 27 |
# File 'lib/ruby_on_ruby/context.rb', line 24 def eval(str) @v8_context['lastInput'] = str @v8_context.eval "Ruby.stringify(Ruby.eval(lastInput))" end |
#js_eval(str) ⇒ Object
29 30 31 |
# File 'lib/ruby_on_ruby/context.rb', line 29 def js_eval(str) @v8_context.eval str end |