Class: Class::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/gherkin/native/therubyracer.rb

Instance Method Summary collapse

Constructor Details

#initialize(js, *args) ⇒ Proxy

Returns a new instance of Proxy.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gherkin/native/therubyracer.rb', line 20

def initialize(js, *args)
  cxt = V8::Context.new
  cxt['module'] = {}

  # Mimic Node.js / Firebug console.log
  cxt['console'] = STDOUT
  def STDOUT.log(*a)
    puts sprintf(*a)
  end

  cxt.load(js)
  @js_obj = cxt['module']['exports'].new(*args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



34
35
36
37
# File 'lib/gherkin/native/therubyracer.rb', line 34

def method_missing(name, *args)
  a = args.map{|a| a.respond_to?(:to_hash) ? a.to_hash : a}
  @js_obj.__send__(name, *a)
end