Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Retains those elements for which the block returns a truthy value; deletes all other elements; returns self:
a = [:foo, 'bar', 2, :bam]
a.keep_if {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
Returns a new Enumerator if no block given:
a = [:foo, 'bar', 2, :bam]
a.keep_if # => #<Enumerator: [:foo, "bar", 2, :bam]:keep_if>
               static VALUE
rb_ary_keep_if(VALUE ary)
    RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
    return ary;

Was this page useful?