HI guys,

Sorry to bring up an old topic as I found out about this class just
recently.  While going over exercise 4.4, it took me a while to figure out
everything that was going on.  I DO understand it all now (after some
research), but was hoping to find out more information about inject which I
wasn't able to find online.

Here is a sample code I found explaining inject.  While I understand the
usage, I am confused with how this code below works:

hash = [[:first_name, 'Shane'], [:last_name, 'Harvie']].inject({}) do
|result, element|
  result[element.first] = element.last
  result
end

>From my reading, I understand that inject iterates through each element.
Now in this above example, you have an array of an array.  What I'm confused
about is why inject grabs the first two elements (:first_name and Shane).
Maybe I just do not understand correctly the concept of array of arrays?
Being that there is 4 elements total, I would have thought element would
only include the symbol :first_name the first time it was run.

Can someone explain this one to me?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to