Class: Mustang::V8::Array
- Includes:
- Comparable, Delegated, Enumerable
- Defined in:
- lib/mustang/v8/array.rb,
ext/v8/v8_array.cpp
Class Method Summary collapse
-
.new(data) ⇒ Object
Returns a new V8 array.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Appends given value to referenced array.
- #<=>(other) ⇒ Object
-
#[](key) ⇒ Object
Returns value of specified array entry.
-
#[]=(key, value) ⇒ Object
Sets given value under specified key.
- #delegate ⇒ Object
- #each(*args, &block) ⇒ Object
-
#get(key) ⇒ Object
Returns value of specified array entry.
- #kind_of?(klass) ⇒ Boolean
-
#length ⇒ Object
Returns number of items stored in this array.
-
#push(value) ⇒ Object
Appends given value to referenced array.
-
#set(key, value) ⇒ Object
Sets given value under specified key.
-
#size ⇒ Object
Returns number of items stored in this array.
-
#to_a ⇒ Array
Returns referenced array data represented as ruby array.
Methods included from Delegated
#method_missing, #old_method_missing, #old_respond_to?, #respond_to?, #to_s
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Delegated
Class Method Details
.V8::Array.new ⇒ Object .V8::Array.new(array) ⇒ Object
Returns a new V8 array.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'ext/v8/v8_array.cpp', line 36
static VALUE rb_v8_array_new(VALUE klass, VALUE data)
{
HandleScope scope;
PREVENT_CREATION_WITHOUT_CONTEXT();
VALUE ary = rb_funcall2(data, rb_intern("to_a"), 0, NULL);
VALUE self = v8_ref_new(klass, to_v8_array(ary));
v8_set_peer(self);
return self;
}
|
Instance Method Details
#push(value) ⇒ Object #<<(value) ⇒ Object
Appends given value to referenced array.
109 110 111 112 113 114 115 116 |
# File 'ext/v8/v8_array.cpp', line 109
static VALUE rb_v8_array_push(VALUE self, VALUE value)
{
HandleScope scope;
Handle<Value> _value = to_v8(value);
Handle<Array> ary = unwrap(self);
ary->Set(ary->Length(), _value);
return to_ruby(_value);
}
|
#<=>(other) ⇒ Object
8 9 10 |
# File 'lib/mustang/v8/array.rb', line 8 def <=>(other) to_a <=> other end |
#[](key) ⇒ Object #get(key) ⇒ Object
Returns value of specified array entry.
ary = cxt.evaluate("['foo', 'bar'];")
ary[0] # => 'foo'
79 80 81 82 83 |
# File 'ext/v8/v8_array.cpp', line 79
static VALUE rb_v8_array_get(VALUE self, VALUE key)
{
HandleScope scope;
return to_ruby(unwrap(self)->Get(NUM2UINT(key)));
}
|
#[]=(key) ⇒ Object #set(key, value) ⇒ Object
Sets given value under specified key.
93 94 95 96 97 98 99 |
# File 'ext/v8/v8_array.cpp', line 93
static VALUE rb_v8_array_set(VALUE self, VALUE key, VALUE value)
{
HandleScope scope;
Handle<Value> _value = to_v8(value);
unwrap(self)->Set(NUM2UINT(key), _value);
return to_ruby(_value);
}
|
#delegate ⇒ Object
16 17 18 |
# File 'lib/mustang/v8/array.rb', line 16 def delegate to_a end |
#each(*args, &block) ⇒ Object
12 13 14 |
# File 'lib/mustang/v8/array.rb', line 12 def each(*args, &block) to_a.each(*args, &block) end |
#[](key) ⇒ Object #get(key) ⇒ Object
Returns value of specified array entry.
ary = cxt.evaluate("['foo', 'bar'];")
ary[0] # => 'foo'
79 80 81 82 83 |
# File 'ext/v8/v8_array.cpp', line 79
static VALUE rb_v8_array_get(VALUE self, VALUE key)
{
HandleScope scope;
return to_ruby(unwrap(self)->Get(NUM2UINT(key)));
}
|
#kind_of?(klass) ⇒ Boolean
20 21 22 |
# File 'lib/mustang/v8/array.rb', line 20 def kind_of?(klass) klass == ::Array or super(klass) end |
#length ⇒ Object #size ⇒ Object
Returns number of items stored in this array.
130 131 132 133 134 |
# File 'ext/v8/v8_array.cpp', line 130
VALUE rb_v8_array_length(VALUE self)
{
HandleScope scope;
return to_ruby(unwrap(self)->Length());
}
|
#push(value) ⇒ Object #<<(value) ⇒ Object
Appends given value to referenced array.
109 110 111 112 113 114 115 116 |
# File 'ext/v8/v8_array.cpp', line 109
static VALUE rb_v8_array_push(VALUE self, VALUE value)
{
HandleScope scope;
Handle<Value> _value = to_v8(value);
Handle<Array> ary = unwrap(self);
ary->Set(ary->Length(), _value);
return to_ruby(_value);
}
|
#[]=(key) ⇒ Object #set(key, value) ⇒ Object
Sets given value under specified key.
93 94 95 96 97 98 99 |
# File 'ext/v8/v8_array.cpp', line 93
static VALUE rb_v8_array_set(VALUE self, VALUE key, VALUE value)
{
HandleScope scope;
Handle<Value> _value = to_v8(value);
unwrap(self)->Set(NUM2UINT(key), _value);
return to_ruby(_value);
}
|
#length ⇒ Object #size ⇒ Object
Returns number of items stored in this array.
130 131 132 133 134 |
# File 'ext/v8/v8_array.cpp', line 130
VALUE rb_v8_array_length(VALUE self)
{
HandleScope scope;
return to_ruby(unwrap(self)->Length());
}
|
#to_a ⇒ Array
Returns referenced array data represented as ruby array.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'ext/v8/v8_array.cpp', line 55
static VALUE rb_v8_array_to_a(VALUE self)
{
HandleScope scope;
VALUE ary = rb_ary_new();
Handle<Array> v8ary = unwrap(self);
for (unsigned int i = 0; i < v8ary->Length(); i++) {
rb_ary_store(ary, i, to_ruby(v8ary->Get(i)));
}
return ary;
}
|