From: Daniel Carrera Date: 2003-02-28T06:08:17+09:00 Subject: Re: 'each' returning array Would Array#map do what you want? >> %w{ H A L } => ["H", "A", "L"] >> %w{ H A L }.map {|x| (x[0]+1).chr} => ["I", "B", "M"] On Fri, Feb 28, 2003 at 06:01:31AM +0900, Wojciech Kaczmarek wrote: > A newbie problem: > > Is there a way to transparently accumulate expresions evaluated within > a block into an array, without introducing an external variable? For > example, I'd like to write something like this: > > "HAL".each_byte__returning_array {|x| (x+1).chr} .collect # more processing > > ...instead of this: > > l=[]; "HAL".each_byte {|x| l<< (x+1).chr}; l.collect #... > > One of my first impressions with ruby was the surprise that each* > method family doesn't return such accumulated arrays just for method > chaining. > > Am I thinking totally non-rubyish? ;-) If so, please show me the Right > Way.. > > -- > He who foos last foos best > -- Daniel Carrera Graduate Teaching Assistant. Math Dept. University of Maryland. (301) 405-5137