Class: Rhino::Ruby::Constructor
- Includes:
- JS::Wrapper
- Defined in:
- lib/rhino/ruby.rb
Class Method Summary collapse
-
.wrap(klass, scope = nil) ⇒ Object
wrap a ruby class as as constructor function.
Instance Method Summary collapse
-
#getLength ⇒ Object
override int BaseFunction#getLength().
-
#hasInstance(instance) ⇒ Object
override boolean Scriptable#hasInstance(Scriptable instance);.
-
#initialize(klass, scope) ⇒ Constructor
constructor
A new instance of Constructor.
- #unwrap ⇒ Object
Methods inherited from Function
#call, #equivalentValues, #getArity, #getFunctionName
Methods included from Scriptable
access, access=, #get, #getIds, #has, #put
Constructor Details
#initialize(klass, scope) ⇒ Constructor
Returns a new instance of Constructor.
221 222 223 224 |
# File 'lib/rhino/ruby.rb', line 221 def initialize(klass, scope) super(klass.method(:new), scope) @klass = klass end |
Class Method Details
.wrap(klass, scope = nil) ⇒ Object
wrap a ruby class as as constructor function
215 216 217 218 219 |
# File 'lib/rhino/ruby.rb', line 215 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 |
Instance Method Details
#getLength ⇒ Object
override int BaseFunction#getLength()
231 232 233 234 |
# File 'lib/rhino/ruby.rb', line 231 def getLength arity = @klass.instance_method(:initialize).arity arity < 0 ? ( arity + 1 ).abs : arity end |
#hasInstance(instance) ⇒ Object
override boolean Scriptable#hasInstance(Scriptable instance);
237 238 239 240 241 |
# File 'lib/rhino/ruby.rb', line 237 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 ⇒ Object
226 227 228 |
# File 'lib/rhino/ruby.rb', line 226 def unwrap @klass end |