On Feb 7, 2008 11:07 PM, Russell Me <russ / geekwhiz.com> wrote:
> kitty_toys.sort_by { |toy| toy[:shape] }.each do |toy|
>    puts "Blixy has a #{ toy[:shape] } made of #{ toy[:fabric] }"
>  end
>
> So in this case (with the sort_by) I gather that a sorted array is being
> thrown into |toy|, and then for each item in |toy| it's key and value
> are printed out by the puts statement? does that about sum it up?  is it
> for each item in the array (that is, getting the number 3) or somehow
> incrementing through?

No. sort_by is taking the block and for each item in the array, it
puts that item into |toy|, and then grabs the :shape from it. it
knows, because of it's nature as sort_by that this is the value you
want compared between all the elements, and so it does so, and returns
the sorted array for .each to be called on. Does that make any sense?
Once you get this, I promise you will love the concept.


Ben