Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Calls the block, if given 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]! {|element| element.to_s.start_with?('b') } # => ["bar", :bam]
Returns nil if no elements were removed.
Returns a new Enumerator if no block given:
a = [:foo, 'bar', 2, :bam]! # => #<Enumerator: [:foo, "bar", 2, :bam]:select!>
Array#filter! is an alias for Array#select!.
               static VALUE
rb_ary_select_bang(VALUE ary)
    struct select_bang_arg args;

    RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);

    args.ary = ary;
    args.len[0] = args.len[1] = 0;
    return rb_ensure(select_bang_i, (VALUE)&args, select_bang_ensure, (VALUE)&args);

Was this page useful?