require 'set' s = %w[ant ape cow hen hog].to_set # A set of words s.divide {|x,y| x[0] == y[0]} # Divide into subsets by first letter # => #<Set:{#<Set:{"hog", "hen"}>, #<Set:{"cow"}>, #<Set:{"ape", "ant"}>}>