From: Aaron Haas Date: 2010-11-13T21:17:14+09:00 Subject: Re: help sorting objects by their instance field Good morning all and thanks again for the help. I re-did the print method as you suggested but it is not sorting by the persons last name. It is just printing in the order in which they were added to array. Here is my print method # sort and print addresses in alphabetical order def print_addresses @persons.sort_by {|person| person.lname} # sorts list by lname @persons.each { |p| puts p } # prints address book end For a good Saturday morning laugh I included my query method. It takes a name and returns any matches found. It actually works fine!!! But I'm sure it could be written in 2 or 3 lines rather than the 13 lines it took me. I wrote this before your help yesterday so I still made use of my get method. # query by name # method is case sensitive # prints each name that matched search parameter def query(name) i = 0 match_counter = 0 # iterate over the entire address book while (i < @persons.length) # set names to match with parameter name first_name = @persons[i].get_fname last_name = @persons[i].get_lname whole_name = first_name + " " + last_name # if name matched print it. if (last_name.eql?(name)) || (first_name.eql?(name)) || (whole_name.eql?(name)) then puts @persons[i].to_s match_counter += 1 end i += 1 end # tell how many matches found puts "Found #{match_counter} matches for that name." end -- Posted via http://www.ruby-forum.com/.