Class: RbPod::Collection
- Inherits:
-
Object
- Object
- RbPod::Collection
- Includes:
- Enumerable
- Defined in:
- ext/rbpod/collection.c
Instance Method Summary collapse
Instance Method Details
#[](key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'ext/rbpod/collection.c', line 19 static VALUE rbpod_collection_get(VALUE self, VALUE key) { struct collection *collection = TYPED_DATA_PTR(self, struct collection); GList *current = NULL; if (FIXNUM_P(key) == FALSE) { return Qnil; } current = g_list_nth(collection->list, FIX2INT(key)); return Data_Wrap_Struct(collection->klass, NULL, NULL, (void *) current->data); } |
#each ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'ext/rbpod/collection.c', line 63 static VALUE rbpod_collection_each(VALUE self) { struct collection *collection = TYPED_DATA_PTR(self, struct collection); GList *current = NULL; VALUE item; if (rb_block_given_p() == FALSE) { return rb_funcall(self, rb_intern("enum_for"), 1, ID2SYM(rb_intern("each"))); } /* If we were supplied a block, enumerate the entire list. */ for (current = collection->list; current != NULL; current = current->next) { item = Data_Wrap_Struct(collection->klass, NULL, NULL, (void *) current->data); rb_yield(item); } return Qnil; } |
#first ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'ext/rbpod/collection.c', line 45 static VALUE rbpod_collection_first(VALUE self) { struct collection *collection = TYPED_DATA_PTR(self, struct collection); GList *current = g_list_first(collection->list); if (current == NULL) { return Qnil; } return Data_Wrap_Struct(collection->klass, NULL, NULL, (void *) current->data); } |
#last ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'ext/rbpod/collection.c', line 33 static VALUE rbpod_collection_last(VALUE self) { struct collection *collection = TYPED_DATA_PTR(self, struct collection); GList *current = g_list_last(collection->list); if (current == NULL) { return Qnil; } return Data_Wrap_Struct(collection->klass, NULL, NULL, (void *) current->data); } |
#length ⇒ Object Also known as: size
57 58 59 60 61 |
# File 'ext/rbpod/collection.c', line 57 static VALUE rbpod_collection_length(VALUE self) { struct collection *collection = TYPED_DATA_PTR(self, struct collection); return INT2NUM(g_list_length(collection->list)); } |