Method: Array#keep_if
- Defined in:
- array.c
#keep_if {|element| ... } ⇒ self #keep_if ⇒ Object
With a block given, calls the block with each element of self
; removes the element from self
if the block does not return a truthy value:
a = [:foo, 'bar', 2, :bam]
a.keep_if {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
With no block given, returns a new Enumerator.
Related: see Methods for Deleting.
3989 3990 3991 3992 3993 3994 3995 |
# File 'array.c', line 3989
static VALUE
rb_ary_keep_if(VALUE ary)
{
RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
rb_ary_select_bang(ary);
return ary;
}
|