47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'ext/cumo/narray/struct.c', line 47
static VALUE
nst_definition(VALUE nst, VALUE idx)
{
long i;
VALUE def = nst_definitions(rb_obj_class(nst));
long len = RARRAY_LEN(def);
if (TYPE(idx) == T_STRING || TYPE(idx) == T_SYMBOL) {
ID id = rb_to_id(idx);
for (i=0; i<len; i++) {
VALUE key = RARRAY_AREF(RARRAY_AREF(def,i),0);
if (SYM2ID(key) == id) {
return RARRAY_AREF(def,i);
}
}
} else if (rb_obj_is_kind_of(idx,rb_cNumeric)) {
i = NUM2LONG(idx);
if (i<-len || i>=len) {
rb_raise(rb_eIndexError,"offset %ld out of range of struct(size:%ld)", i, len);
}
return RARRAY_AREF(def,i);
}
return Qnil;
}
|