Class: Ray::GL::IntArray
- Inherits:
-
Object
- Object
- Ray::GL::IntArray
- Includes:
- Enumerable
- Defined in:
- lib/ray/gl/int_array.rb,
ext/gl_int_array.c
Instance Method Summary collapse
- #<<(val) ⇒ self
- #[](i) ⇒ Integer?
- #[]=(i, val) ⇒ Object
-
#clear ⇒ Object
Removes all the elements from the array.
- #each ⇒ Object
- #each_index {|i| ... } ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #initialize_copy(orig) ⇒ Object
- #map! {|val| ... } ⇒ Object
-
#size ⇒ Integer
Size of the array.
Constructor Details
#initialize(*args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'ext/gl_int_array.c', line 32
static
VALUE ray_int_array_init(int argc, VALUE *argv, VALUE self) {
say_array *ary = ray_rb2int_array(self);
for (int i = 0; i < argc; i++) {
int val = NUM2INT(argv[i]);
say_array_push(ary, &val);
}
return self;
}
|
Instance Method Details
#<<(val) ⇒ self
55 56 57 58 59 60 61 62 63 64 65 |
# File 'ext/gl_int_array.c', line 55
static
VALUE ray_int_array_push(VALUE self, VALUE val) {
rb_check_frozen(self);
say_array *ary = ray_rb2int_array(self);
int e = NUM2INT(val);
say_array_push(ary, &e);
return self;
}
|
#[](i) ⇒ Integer?
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'ext/gl_int_array.c', line 72
static
VALUE ray_int_array_get(VALUE self, VALUE i) {
say_array *ary = ray_rb2int_array(self);
size_t idx = NUM2ULONG(i);
int *elem = say_array_get(ary, idx);
if (elem) {
return INT2FIX(*elem);
}
else
return Qnil;
}
|
#[]=(i, val) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'ext/gl_int_array.c', line 91
static
VALUE ray_int_array_set(VALUE self, VALUE i, VALUE val) {
rb_check_frozen(self);
say_array *ary = ray_rb2int_array(self);
size_t idx = NUM2ULONG(i);
if (say_array_get_size(ary) <= idx)
say_array_resize(ary, idx + 1);
*(int*)say_array_get(ary, idx) = NUM2INT(val);
return val;
}
|
#clear ⇒ Object
Removes all the elements from the array
113 114 115 116 117 |
# File 'ext/gl_int_array.c', line 113 static VALUE ray_int_array_clear(VALUE self) { say_array_resize(ray_rb2int_array(self), 0); return self; } |
#each ⇒ Object
6 7 8 |
# File 'lib/ray/gl/int_array.rb', line 6 def each (0...size).each { |i| yield self[i] } end |
#each_index {|i| ... } ⇒ Object
19 20 21 |
# File 'lib/ray/gl/int_array.rb', line 19 def each_index(&block) (0...size).each(&block) end |
#initialize_copy(orig) ⇒ Object
44 45 46 47 48 |
# File 'ext/gl_int_array.c', line 44
static
VALUE ray_int_array_init_copy(VALUE self, VALUE orig) {
say_array_copy(ray_rb2int_array(self), ray_rb2int_array(orig));
return self;
}
|
#map! {|val| ... } ⇒ Object
13 14 15 |
# File 'lib/ray/gl/int_array.rb', line 13 def map! (0...size).each { |i| self[i] = yield self[i] } end |
#size ⇒ Integer
Returns size of the array.
107 108 109 110 |
# File 'ext/gl_int_array.c', line 107 static VALUE ray_int_array_size(VALUE self) { return INT2FIX(say_array_get_size(ray_rb2int_array(self))); } |