Class: Jscall::Exported
- Inherits:
-
Object
- Object
- Jscall::Exported
- Defined in:
- lib/jscall.rb
Overview
inbound referneces from Node to Ruby
Instance Attribute Summary collapse
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
Instance Method Summary collapse
- #export(obj) ⇒ Object
- #find(idx) ⇒ Object
-
#initialize ⇒ Exported
constructor
A new instance of Exported.
- #remove(idx) ⇒ Object
Constructor Details
Instance Attribute Details
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
40 41 42 |
# File 'lib/jscall.rb', line 40 def objects @objects end |
Instance Method Details
#export(obj) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/jscall.rb', line 50 def export(obj) hash = @hashtable.__getobj__ if hash.include?(obj) hash[obj] else objs = @objects.__getobj__ idx = @free_element if idx < 0 idx = objs.size else @free_element = objs[idx] end objs[idx] = obj hash[obj] = idx # return idx end end |
#find(idx) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/jscall.rb', line 67 def find(idx) obj = @objects.__getobj__[idx] if obj.is_a?(Numeric) raise JavaScriptError.new("unknown index is given to find(): #{idx}") else obj end end |
#remove(idx) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jscall.rb', line 76 def remove(idx) objects = @objects.__getobj__ obj = objects[idx] if obj.is_a?(Numeric) raise JavaScriptError.new("unknown index is given to remove(): #{idx}") else objects[idx] = @free_element @free_element = idx @hashtable.__getobj__.delete(obj) end end |