From: Chad Perrin Date: 2007-12-14T10:43:17+09:00 Subject: Re: How To Avoid Ugly Declerations On Thu, Dec 13, 2007 at 05:16:24AM +0900, Michael Boutros wrote: > Thanks so much for all the replies :) So, what I've gathered is that map > basically loops through all the values of an array, does whatever the > block says to do, and then places it back into the array. Correct? If I understand your sentence correctly -- no, that's incorrect. My understanding is that you expect #map or #collect to do this: foo = %w(rgb irs rib) foo.map {|f| f.gsub('r', 'e')} puts foo > egb > ies > eib What it actually does is this: foo = %w(rgb irs rib) bar = foo.map {|f| f.gsub('r', 'e')} puts foo > rgb > irs > rib puts bar > egb > ies > eib Thus, the proposed method declaration: def some_method(foo) foo.map { |f| f.reverse } end . . . would return the reversed list, exactly the same as a version with an explicit return statement. It does not alter the provided variable at all, but instead outputs a brand-new list object. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] They always say that when life gives you lemons you should make lemonade. I always wonder -- isn't the lemonade going to suck if life doesn't give you any sugar?