class Rhino::Ruby::Constructor

Public Class Methods

new(klass, scope) click to toggle source
Calls superclass method Rhino::Ruby::Function::new
# File lib/rhino/ruby.rb, line 225
def initialize(klass, scope)
  super(klass.method(:new), scope)
  @klass = klass
end
wrap(klass, scope = nil) click to toggle source

wrap a ruby class as as constructor function

# File lib/rhino/ruby.rb, line 219
def self.wrap(klass, scope = nil)
  # 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, scope) }
end

Public Instance Methods

getLength() click to toggle source

override int BaseFunction#getLength()

# File lib/rhino/ruby.rb, line 235
def getLength
  arity = @klass.instance_method(:initialize).arity
  arity < 0 ? ( arity + 1 ).abs : arity
end
hasInstance(instance) click to toggle source

override boolean Scriptable#hasInstance(Scriptable instance);

# File lib/rhino/ruby.rb, line 241
def hasInstance(instance)
  return false unless instance
  return true if instance.is_a?(@klass)
  instance.is_a?(Object) && instance.unwrap.is_a?(@klass)
end
unwrap() click to toggle source
# File lib/rhino/ruby.rb, line 230
def unwrap
  @klass
end