Class: V8::Array

Inherits:
Object show all
Defined in:
lib/v8/array.rb

Instance Attribute Summary

Attributes inherited from Object

#native

Instance Method Summary collapse

Methods inherited from Object

#[], #[]=, #keys, #method_missing, #respond_to?, #to_s, #values

Constructor Details

#initialize(native_or_length = nil) ⇒ Array

Returns a new instance of Array.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/v8/array.rb', line 3

def initialize(native_or_length = nil)
  super do
    if native_or_length.is_a?(Numeric)
      V8::C::Array::New(native_or_length)
    elsif native_or_length.is_a?(V8::C::Array)
      native_or_length
    else
      V8::C::Array::New()
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class V8::Object

Instance Method Details

#eachObject



15
16
17
18
19
20
21
# File 'lib/v8/array.rb', line 15

def each
  @context.enter do
    0.upto(@native.Length() - 1) do |i|
      yield @context.to_ruby(@native.Get(i))
    end
  end
end

#lengthObject



23
24
25
# File 'lib/v8/array.rb', line 23

def length
  @native.Length()
end