T
Tim Conner
simple question: how can I do a collect with index? This should be
like each_with_index but should return a new array containing the values
returned by the block.
i.e
Say i want to return:
["cat number 1","dog number 2","pig number 3"
how would i do this? I am thinking that there must be something along
the lines of:
%w{"cat","dog","pig"}.collect_with_index {|animal,index| animal+" number
"+index}
but I can't find a 'collect_with_index' in the documentation. How would
I do this?
Thanks
like each_with_index but should return a new array containing the values
returned by the block.
i.e
Say i want to return:
["cat number 1","dog number 2","pig number 3"
how would i do this? I am thinking that there must be something along
the lines of:
%w{"cat","dog","pig"}.collect_with_index {|animal,index| animal+" number
"+index}
but I can't find a 'collect_with_index' in the documentation. How would
I do this?
Thanks