Class: Warts::List
Instance Attribute Summary collapse
- #element_type ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#derive(*args) ⇒ Object
nothing to do: users shouldn’t write lists themselves.
- #initialize ⇒ Object constructor
- #write_to(file) ⇒ Object
Constructor Details
#initialize ⇒ Object
110 111 112 113 114 |
# File 'ext/sclist.c', line 110
static VALUE sclist_init(VALUE self)
{
rb_ivar_set(self, iv_element_type, INT2FIX(SCAMPER_FILE_OBJ_LIST));
return self;
}
|
Instance Attribute Details
#element_type ⇒ Object (readonly)
Class Method Details
.create(options) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'ext/sclist.c', line 188
static VALUE sclist_s_create(VALUE klass, VALUE options)
{
scamper_list_t *list;
VALUE option;
unsigned int id;
char* name;
char* descr;
char* monitor;
VALUE retval;
if (TYPE(options) != T_HASH) {
rb_raise(rb_eTypeError, "wrong argument type -- expected hash");
}
option = rb_hash_aref(options, sym_id);
id = (NIL_P(option) ? 0 : NUM2UINT(option));
EXTRACT_STR_OPTION(list, name);
EXTRACT_STR_OPTION(list, descr);
EXTRACT_STR_OPTION(list, monitor);
list = scamper_list_alloc(id, name, descr, monitor);
if (!list) {
return Qnil;
}
retval = Data_Wrap_Struct(cList, 0, sclist_free, list);
if (NIL_P(sclist_init(retval))) {
scamper_list_free(list);
return Qnil;
}
return retval;
}
|
Instance Method Details
#<=>(other) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'ext/sclist.c', line 117
static VALUE sclist_cmp(VALUE self, VALUE other)
{
scamper_list_t *self_list;
scamper_list_t *other_list;
if (other == self) {
return INT2FIX(0);
}
/* See Pragmatic Programmer's book. */
if (TYPE(other) != T_DATA || RDATA(other)->dfree != sclist_free) {
rb_raise(rb_eTypeError, "wrong argument type");
}
Data_Get_Struct(self, scamper_list_t, self_list);
Data_Get_Struct(other, scamper_list_t, other_list);
return INT2FIX(self_list->id < other_list->id ? -1
: (self_list->id > other_list->id ? 1 : 0));
}
|
#derive(*args) ⇒ Object
nothing to do: users shouldn’t write lists themselves
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'ext/sclist.c', line 145
static VALUE sclist_derive(int argc, VALUE *argv, VALUE self)
{
scamper_list_t *self_list;
scamper_list_t *list;
VALUE options, option;
unsigned int id;
char* name;
char* descr;
char* monitor;
VALUE retval;
if (rb_scan_args(argc, argv, "01", &options) == 0) {
options = rb_hash_new();
}
Data_Get_Struct(self, scamper_list_t, self_list);
if (TYPE(options) != T_HASH) {
rb_raise(rb_eTypeError, "wrong argument type -- expected hash");
}
option = rb_hash_aref(options, sym_id);
id = (NIL_P(option) ? self_list->id : NUM2UINT(option));
EXTRACT_STR_OPTION(self_list, name);
EXTRACT_STR_OPTION(self_list, descr);
EXTRACT_STR_OPTION(self_list, monitor);
list = scamper_list_alloc(id, name, descr, monitor);
if (!list) {
return Qnil;
}
retval = Data_Wrap_Struct(cList, 0, sclist_free, list);
if (NIL_P(sclist_init(retval))) {
scamper_list_free(list);
return Qnil;
}
return retval;
}
|
#write_to(file) ⇒ Object
139 140 141 142 |
# File 'ext/sclist.c', line 139
static VALUE sclist_write_to(VALUE self, VALUE file)
{
return self; /* nothing to do: users shouldn't write lists themselves */
}
|