Method: Array#filter!
- Defined in:
- array.c
#select! {|element| ... } ⇒ self? #select! ⇒ Object #filter! {|element| ... } ⇒ self? #filter! ⇒ Object
With a block given, calls the block with each element of self
; removes from self
those elements for which the block returns false
or nil
.
Returns self
if any elements were removed:
a = [:foo, 'bar', 2, :bam]
a.select! {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
Returns nil
if no elements were removed.
With no block given, returns a new Enumerator.
Related: see Methods for Deleting.
3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 |
# File 'array.c', line 3960
static VALUE
rb_ary_select_bang(VALUE ary)
{
struct select_bang_arg args;
RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
rb_ary_modify(ary);
args.ary = ary;
args.len[0] = args.len[1] = 0;
return rb_ensure(select_bang_i, (VALUE)&args, select_bang_ensure, (VALUE)&args);
}
|