Class: JavaScript::Prototype

Inherits:
Object show all
Defined in:
lib/javascript.rb

Instance Method Summary collapse

Methods inherited from Object

#!=, #==, #===, #[], #[]=, #__defined__?, #__hash__, #__proto__

Constructor Details

#initialize(klass) ⇒ Prototype

Returns a new instance of Prototype.



291
292
293
294
# File 'lib/javascript.rb', line 291

def initialize(klass)
  super(nil)
  @klass = klass
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



297
298
299
300
301
302
303
304
# File 'lib/javascript.rb', line 297

def method_missing(name, *args, &block)
  meth = @klass.instance_method(name)
  args = meth.parameters.map { |_, name| name && Identifier.new(name) }.compact
  body = ->(*args) { meth.bind(this).call(*args) }
  Function.new(name, args, body)
rescue NameError
  super
end