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
34 35 36 37 38 39 40 41 42 43 44 |
# File 'ext/gl_int_array.c', line 34
static
VALUE ray_int_array_init(int argc, VALUE *argv, VALUE self) {
mo_array *ary = ray_rb2int_array(self);
for (int i = 0; i < argc; i++) {
GLint val = NUM2INT(argv[i]);
mo_array_push(ary, &val);
}
return self;
}
|
Instance Method Details
#<<(val) ⇒ self
57 58 59 60 61 62 63 64 65 66 67 |
# File 'ext/gl_int_array.c', line 57
static
VALUE ray_int_array_push(VALUE self, VALUE val) {
rb_check_frozen(self);
mo_array *ary = ray_rb2int_array(self);
GLint e = NUM2INT(val);
mo_array_push(ary, &e);
return self;
}
|
#[](i) ⇒ Integer?
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/gl_int_array.c', line 74
static
VALUE ray_int_array_get(VALUE self, VALUE i) {
mo_array *ary = ray_rb2int_array(self);
size_t idx = NUM2ULONG(i);
GLint *elem = mo_array_get_ptr(ary, idx, GLint);
if (elem) {
return INT2FIX(*elem);
}
else
return Qnil;
}
|
#[]=(i, val) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'ext/gl_int_array.c', line 93
static
VALUE ray_int_array_set(VALUE self, VALUE i, VALUE val) {
rb_check_frozen(self);
mo_array *ary = ray_rb2int_array(self);
size_t idx = NUM2ULONG(i);
if (ary->size <= idx)
mo_array_resize(ary, idx + 1);
mo_array_get_as(ary, idx, GLint) = NUM2INT(val);
return val;
}
|
#clear ⇒ Object
Removes all the elements from the array
115 116 117 118 119 |
# File 'ext/gl_int_array.c', line 115 static VALUE ray_int_array_clear(VALUE self) { mo_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
46 47 48 49 50 |
# File 'ext/gl_int_array.c', line 46
static
VALUE ray_int_array_init_copy(VALUE self, VALUE orig) {
mo_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.
109 110 111 112 |
# File 'ext/gl_int_array.c', line 109
static
VALUE ray_int_array_size(VALUE self) {
return INT2FIX(ray_rb2int_array(self)->size);
}
|