From: Russell Me Date: 2008-02-08T05:56:25+09:00 Subject: Re: info on block arguments tho_mica_l wrote: >> I think of a block as Cookiemonster from Sesame street. When you throw >> something at him, he will name it "cookie" and then eat it. In this case >> you throw each element of kitty_toys, the block will call them all "toy" >> and process them. > > Unfortunately, my knowledge of Sesame Street is rather limited. But I > think you're forgetting something. I'm quite sure there is something > or someone sitting between you and the Cookiemonster, let's call it/ > him/her Sorty. Sorty takes all the kitty_toys from you and hands one > toy after the other over to the Cookiemonster. So the Cookiemonster > doesn't get them all at once but only one at a time. That's because it > is a well educated Cookiemonster that doesn't eat two cookies at a > time. Sorty then takes the toys back from the Cookiemonster and hands > them over to Mrs. Each. > > Nice analogy. Thank you both for your help. it's making more sense but i imagine it should make total sense to me, no? Still not 100% though about it and I certainly hope this isn't a preview of things to come. Things have been going well until i hit this simple roadblock of understanding. >>>kitty_toys.sort_by { |toy| toy[:shape] }.each do |toy| >>> puts "Blixy has a #{ toy[:shape] } made of #{ toy[:fabric] }" >>> end ok, so i see that a sort is being performed on kitty toys with "kitty_toys.sort_by". but what's the next bit about? namely: { |toy| toy[:shape] }.each do |toy| I see that the sort is based on the shape from toy[:shape] but how? and what is the "|toy|" before it doing? and then i assume that the .each means do it for all the items, right? and then... for each toy, output the puts bit? (which then get's sorted by the sort_by)? Sorry to be a bother with something so trivial. -- Posted via http://www.ruby-forum.com/.