Class: Mochiscript::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/mochiscript/core.rb

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



6
7
8
9
10
# File 'lib/mochiscript/core.rb', line 6

def initialize
  @ctx = V8::Context.new
  @ctx['_$m_adapter'] = Adapter.new
  @ctx.eval(Parser::JAVASCRIPT)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



30
31
32
# File 'lib/mochiscript/core.rb', line 30

def method_missing(name, *args, &block)
  @ctx.send(name, *args, &block)
end

Instance Method Details

#eval_ms(str) ⇒ Object



24
25
26
# File 'lib/mochiscript/core.rb', line 24

def eval_ms(str)
  @ctx.eval(parse(str))
end

#parse(str) ⇒ Object



12
13
14
# File 'lib/mochiscript/core.rb', line 12

def parse(str)
  @ctx.eval("$m.parse(#{str.to_json})")
end

#pp(str) ⇒ Object



20
21
22
# File 'lib/mochiscript/core.rb', line 20

def pp(str)
  return @ctx.eval("$m.pp(#{str.to_json})")
end

#to_json(str) ⇒ Object



16
17
18
# File 'lib/mochiscript/core.rb', line 16

def to_json(str)
  @ctx.eval("$m.toJSON(#{str.to_json})")
end