arrays - Ruby Select and Reject in one method -
is there built in method combine functions of select (find block equates true) , reject (find block equates false)?
something like
good, bad = list.magic_method { |obj| obj.good? }
wouldn't hard myself nih , that. :)
looks if enumerable.partition
after.
= enumerable.partition (from ruby core) ------------------------------------------------------------------------------ enum.partition {| obj | block } -> [ true_array, false_array ] enum.partition -> an_enumerator ------------------------------------------------------------------------------ returns 2 arrays, first containing elements of enum block evaluates true, second containing rest. if no block given, enumerator returned instead. (1..6).partition {|i| (i&1).zero?} #=> [[2, 4, 6], [1, 3, 5]]
interesting, didn't know there. ri
amazing tool...
Comments
Post a Comment