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



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

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.map(&:to_s))
  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



36
37
38
39
# File 'lib/gherkin/native/therubyracer.rb', line 36

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