Class: Nashorn::Ruby::Object

Inherits:
JS::AbstractJSObject
  • Object
show all
Includes:
Scriptable
Defined in:
lib/nashorn/ruby.rb

Instance Attribute Summary

Attributes included from Scriptable

#unwrap

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Scriptable

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

Constructor Details

#initialize(object) ⇒ Object

Returns a new instance of Object.



123
124
125
126
# File 'lib/nashorn/ruby.rb', line 123

def initialize(object)
  super()
  @unwrap = object
end

Class Method Details

.wrap(object) ⇒ Object

wrap an arbitrary (ruby) object



119
120
121
# File 'lib/nashorn/ruby.rb', line 119

def self.wrap(object)
  Ruby.cache(object) { new(object) }
end

Instance Method Details

#==(other) ⇒ Object



172
173
174
175
176
177
178
# File 'lib/nashorn/ruby.rb', line 172

def ==(other)
  if other.is_a?(Object)
    unwrap == other.unwrap
  else
    unwrap == other
  end
end

#equals(other) ⇒ Object



168
169
170
# File 'lib/nashorn/ruby.rb', line 168

def equals(other)
  other.is_a?(Object) && unwrap.eql?(other.unwrap)
end

#getClassNameObject



129
130
131
# File 'lib/nashorn/ruby.rb', line 129

def getClassName
  @unwrap.class.to_s # to_s handles 'nameless' classes as well
end

#getDefaultValue(hint) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/nashorn/ruby.rb', line 144

def getDefaultValue(hint)
  if hint && NUMBER_CLASS.eql?(hint)
    return hint.to_f if hint.respond_to?(:to_f)
    return hint.to_i if hint.respond_to?(:to_i)
  end
  @unwrap.to_s
end

#hashCodeObject



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

def hashCode; @unwrap.hash end

#isArrayObject



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

def isArray; @unwrap.is_a?(Array) end

#isFunctionObject



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

def isFunction; false end

#isInstance(instance) ⇒ Object



134
135
136
# File 'lib/nashorn/ruby.rb', line 134

def isInstance(instance)
  instance.class.equal? @unwrap
end

#isInstanceOf(clazz) ⇒ Object



139
140
141
# File 'lib/nashorn/ruby.rb', line 139

def isInstanceOf(clazz)
  @unwrap.is_a?(clazz)
end

#isStrictFunctionObject



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

def isStrictFunction; false end

#to_aObject



182
183
184
# File 'lib/nashorn/ruby.rb', line 182

def to_a
  isArray ? @unwrap : super
end

#toStringObject

def newObject(args); fail end



164
165
166
# File 'lib/nashorn/ruby.rb', line 164

def toString
  "[ruby #{getClassName}]" # [object User]
end