Jason Williams
10/27/2003 2:59:00 PM
In article <3f9d303e$0$1114$6c56d894@feed0.news.be.easynet.net>,
Raphael Bauduin wrote:
> Hi,
>
> applying the example found in "ri Array#delete_if":
>
> irb(main):020:0> a = [ "a", "b", "c" ]
>=> ["a", "b", "c"]
> irb(main):021:0> a.delete_if {|x| x >= "b" }
>=> ["a"]
> irb(main):022:0> a
>=> ["a"]
>
> How do I get the elements that where rejected? (Btw, shouldn't this
> method end in a "!" ?)
How about instead;
x,y = a.partition { |x| x >= "b" }
The "!" isn't necessary IMO because "delete" already implies the
destructive in-place effect. The not-in-place version is reject_if.
> As illustration, I'm looking for a way similar to the pure fictional
> method below:
> a = [ "a", "b", "c" ]
> a.keep_if {|x| x >= "b" }
>=> [ "b", "c" ]
a.select { |x| x >= "b" }