Flatten the subsets
require 'set' s = %w[ant ape cow hen hog].to_set # A set of words t = s.divide {|x,y| x[0] == y[0]} # Divide it into subsets t.flatten! # Flatten the subsets t == s # => true