From: Rick DeNatale Date: 2006-10-03T06:07:58+09:00 Subject: Re: Special variable within iterators to hold results? On 10/2/06, Rick DeNatale wrote: > On 10/2/06, Wes Gamble wrote: > > I have this: > > > > FILTER_COLUMNS = Array.new > > DISPLAYABLE_COLUMNS.each do |field_array| > > FILTER_COLUMNS << [ field_array[1], field_array[0] ] > > end > > > > Is there any way to write this so that it could look something like: > > > > FILTER_COLUMNS = DISPLAYABLE_COLUMNS.each do |field_array| > > ??? << [ field_array[1], field_array[0] ] > > end > > > > so that I don't have to bother initializing FILTER_COLUMNS - is there > > some special variable that holds the intermediate result of the iterator > > body? > > filter_columns = displayable_columns.inject([] {| darn that itchy trigger finger. displayable_columns.inject([]) {|result, field_array| result << [field_array[1], field_array[0]]} or assuming that field_array contains two element arrays: displayable_columns.inject([]) {|result, field_array| result << [field_array[1], field_array[0]]} -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/