From: Muhammad Salman Date: 2012-10-11T01:40:51+09:00 Subject: How to create an Array in a Hash Hi, I am new to Ruby and am working on Anagram. So in anagram for the input below # input: ['cars', 'four','scar', 'creams', 'scream', 'scream'] I want an output like this # output: [ ["cars","scar"], # ["four"], # ["creams", "scream", "scream"] ] But i am getting an output like # output: [ ["cars","scar"], # ["four"], # ["creams", "scream"] ] because of Hash property. This is my code. sorted_words = Hash.new(0) words.each { |word| sorted_words[word]=word.downcase.chars.sort { |a, b| a.casecmp(b) }.join } sorted_hash = {} sorted_words.each_pair do |key, value| (sorted_hash[value] ||= []) << key end anagram_array = sorted_hash.values Please advice me (with some code) how to solve this. Thankyou for taking you time out and helping with this amazing language -- Posted via http://www.ruby-forum.com/.