Class: Nashorn::Ruby::Constructor

Inherits:
Function
  • Object
show all
Defined in:
lib/nashorn/ruby.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#==, #arity, #call, #equals, #getDefaultValue, #isInstanceOf, #length

Methods included from Scriptable

#getMember, #getSlot, #hasMember, #hasSlot, #keySet, #removeMember, #setMember, #setSlot

Constructor Details

#initialize(klass) ⇒ Constructor

Returns a new instance of Constructor.



315
316
317
318
# File 'lib/nashorn/ruby.rb', line 315

def initialize(klass)
  super(klass.method(:new))
  @klass = klass
end

Class Method Details

.wrap(klass) ⇒ Object

wrap a ruby class as as constructor function



309
310
311
312
313
# File 'lib/nashorn/ruby.rb', line 309

def self.wrap(klass)
  # NOTE: caching here seems redundant since we implemented JS::Wrapper
  # and a ruby class objects seems always the same ref under JRuby ...
  Ruby.cache(klass) { new(klass) }
end

Instance Method Details

#getClassNameObject



323
# File 'lib/nashorn/ruby.rb', line 323

def getClassName; @klass.name end

#isArrayObject



333
# File 'lib/nashorn/ruby.rb', line 333

def isArray; false end

#isFunctionObject



336
# File 'lib/nashorn/ruby.rb', line 336

def isFunction; true end

#isInstance(instance) ⇒ Object



326
327
328
329
330
# File 'lib/nashorn/ruby.rb', line 326

def isInstance(instance)
  return false unless instance
  return true if instance.is_a?(@klass)
  instance.is_a?(Object) && instance.unwrap.is_a?(@klass)
end

#isStrictFunctionObject



339
# File 'lib/nashorn/ruby.rb', line 339

def isStrictFunction; false end

#newObject(args) ⇒ Object



342
# File 'lib/nashorn/ruby.rb', line 342

def newObject(args); @klass.new(*args) end

#unwrapObject



320
# File 'lib/nashorn/ruby.rb', line 320

def unwrap; @klass end