Похоже, что Enumerable.partition
- это именно то, что вам нужно.
= Enumerable.partition
(from ruby core)
------------------------------------------------------------------------------
enum.partition {| obj | block } -> [ true_array, false_array ]
enum.partition -> an_enumerator
------------------------------------------------------------------------------
Returns two arrays, the first containing the elements of enum for
which the block evaluates to true, the second containing the rest.
If no block is given, an enumerator is returned instead.
(1..6).partition {|i| (i&1).zero?} #=> [[2, 4, 6], [1, 3, 5]]
Интересно, я не знал, что там было. ri
удивительный инструмент ...