From: Robert Klemme Date: 2008-05-28T18:18:46+09:00 Subject: Re: n00b question 2008/5/28 Robert Klemme : > 2008/5/27 Tim Wolak : >> Can someone explain to me why my script is printing the key to my hash >> twice? I need it to print the key then the value on the first iteration >> and on the second iteration it should only print the value. I am >> getting information from two files, the account numbers and balances and >> displaying account number, yesterday balance, today balance and the >> difference. > >> g = my_hash.to_s.sort >> puts g > > You are printing key and value of your hash and since the value also > contains the account number you see it twice. You probably rather > want: > > my_hash.sort.each |k,v| > puts v > end Here's an alternative puts my_hash.values.sort_by {|v| v.account_number} Cheers robert -- use.inject do |as, often| as.you_can - without end