Based on the comment you're looking for an anagram maker, here's the basis for such a beast:
require 'pp'
require 'set'
words = %w[cream scream scream creams]
hash = Hash.new{ |h,k| h[k] = Set.new }
words.each do |w|
hash[w.downcase.split('').sort] << w.downcase
end
pp hash
=> {["a", "c", "e", "m", "r"]=>#<Set: {"cream"}>,
["a", "c", "e", "m", "r", "s"]=>#<Set: {"scream", "creams"}>}
Given a set of words, this will create a hash, where each key is the sorted list of the letters in the word. The value associated with that key is a set of words with the same letters.
Because the value is a set, only unique words are stored.
Once that hash is populated, you'll have a dictionary you can use to quickly look up other words. Take a word, break it down the same way the keys are broken down, and use that as the key in a look-up:
puts hash['creams'.downcase.split('').sort].to_a.join(', ')
outputs:
scream, creams
If duplicate (and redundant) words are needed:
require 'pp'
require 'set'
words = %w[cream creams scream scream]
hash = Hash.new{ |h,k| h[k] = [] }
words.each do |w|
hash[w.downcase.split('').sort] << w.downcase
end
pp hash
=> {["a", "c", "e", "m", "r"]=>["cream"],
["a", "c", "e", "m", "r", "s"]=>["creams", "scream", "scream"]}
puts hash['creams'.downcase.split('').sort].to_a.sort.join(', ')
=> creams, scream, scream