From: James Edward Gray II Date: 2006-01-03T05:16:50+09:00 Subject: Re: New to Ruby and Programming On Jan 2, 2006, at 2:08 PM, Hal Fulton wrote: > Chad Perrin wrote: >> On Tue, Jan 03, 2006 at 12:03:03AM +0900, James Edward Gray II wrote: >>> On Jan 2, 2006, at 2:29 AM, Chad Perrin wrote: >>> >>> >>>> In particular, you could have an array called myarray >>>> (for example) and iterate over its contents using the each >>>> method to >>>> perform the same action on each element of the array: >>>> >>>> myarray.each do { |foo| puts foo } >>> >>> Only we would never write that since the following does the same >>> thing: >>> >>> puts myarray >> Well . . . true. >> This is why I don't teach programming. > > Actually, I think there's a difference in behavior > if you try them both. Other than the return value? >> (1..10).to_a.each { |n| puts n } 1 2 3 4 5 6 7 8 9 10 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> puts (1..10).to_a 1 2 3 4 5 6 7 8 9 10 => nil James Edward Gray II