Mastering Enumerable, Part 1

Flashcard 4 of 7

What is the real name of mystery_method?

(1..6).mystery_method { |i| i.even? }  #=> [[2, 4, 6], [1, 3, 5]]

Another example:

names = %w(mark ben christopher joe)

names.mystery_method { |name| name.length == 3 }
#=> [["ben", "joe"], ["mark", "christopher"]]

The method is partition.

"Returns two arrays, the first containing the elements of enum for which the block evaluates to true, the second containing the rest."

(1..6).partition { |i| i.even? }
#=> [[2, 4, 6], [1, 3, 5]]
Return to Flashcard Results