From: "Jesús Gabriel y Galán" Date: 2010-11-14T07:45:51+09:00 Subject: Re: help sorting objects by their instance field On Sat, Nov 13, 2010 at 11:18 PM, Aaron Haas wrote: > Nathan Clark wrote in post #961001: >> Check the docs for class Array >> http://ruby-doc.org/core/classes/Array.html#M002185 >> >> You can pass a block to array.sort, that tells it what to sort by (in >> your case, person.lname). > > Is this what you mean?  I also tried this and I'm getting the following > error > > def print_addresses(&block) >         @persons.sort_by { |p| persons.lname  } >         @persons.each { |p| yield p } >       end persons is undefined here, you have to use p (btw, I'd use person instead). But I think what Nathan means is what was already said: def print_addresses @persons.sort_by {|person| person.lname}.each {|person| puts person} end He was talking about the block passed to the Array#sort_by method. Jesus.