irb(main):001:0> aers = %w(a b c d ab bc de abc) #=> ["a", "b", "c", "d", "ab", "bc", "de", "abc"] irb(main):002:0> aers.group_by{ |s| s.size } #=> {1=>["a", "b", "c", "d"], 2=>["ab", "bc", "de"], 3=>["abc"]} people.group_by { |p| p['age'] }
(1..6).group_by { |i| i%3 } #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}