ibotty <me / ibotty.net> wrote in message news:<1062154916.838157 / elch.in-berlin.de>...
> before i spent to many words describing something so simple:
> 
> say, i have:
> a = [1,2,3] and b = [4,5,6]
> and i want to get another array, with c[ix] = a[ix] * b[ix].
> (i want to get c = [4,10,18])
> 
> is there a builtin function in array.rb (that i have missed).
> 
> atm, i use a block to traverse thru every single element, but this still
> makes one big or 2 small lines.
> (e. g.: c =[]; a.each_with_index{ |ix| c[ix] = a[ix] * b[ix] } )
> 
> this should be way more elegant ;)


you can use the Enumerable#zip and Enumerable#collect methods:


c = a.zip(b).collect{|a_elt, b_elt| a_elt*b_elt}

i dont see more elegant :)

Ciao
Denis