Method: List#select!

Defined in:
ext/list/list.c

#select!Object



1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
# File 'ext/list/list.c', line 1517

static VALUE
list_select_bang(VALUE self)
{
  VALUE result;
  item_t *c;
  long i = 0;

  RETURN_SIZED_ENUMERATOR(self, 0, 0, list_enum_length);
  result = list_new();
  LIST_FOR(self, c) {
    if (RTEST(rb_yield(c->value))) {
      i++;
      list_push(result, c->value);
    }
  }

  if (i == LIST_LEN(self)) return Qnil;
  return list_replace(self, result);
}