group_by

enum.group_by { |obj| block } â a_hash
enum.group_by â an_enumerator
Instance Public methods

Groups the collection by result of the block. Returns a hash where the keys are the evaluated result from the block and the values are arrays of elements in the collection that correspond to the key.

If no block is given an enumerator is returned.

(1..6).group_by { |i| i%3 }   #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}
doc_ruby_on_rails
2015-04-05 00:33:24
Comments
Leave a Comment

Please login to continue.