On Wed, Jun 11, 2008 at 9:37 PM, Jason Lillywhite <jason.lillywhite / gmail.com> wrote: > I have this simple program that has a problem that I just can't find a > solution to: > *********** > class MyArray > > def count > a = [50.1,52.0,55.0,60.0] > b = [0.24,0.1,0.29,0.9] > i = 0 > c = [] > while i <= 4 do this should be i < 4, however .... > puts c = b.collect {|x| x * a[i]} > i += 1 > end > > end > end > <snip> > I don't understand where 'nil' is coming from. Can someone help me with > this one? Thank you. > -- > Posted via http://www.ruby-forum.com/. > > I'd rather do this like this c = a.zip(b).map{ |a_ele, b_ele| a_ele * b_ele } this will still give an error if b is shorter than a (but in Ruby1.9 a will be cut IIRC). HTH Robert -- http://ruby-smalltalk.blogspot.com/ --- As simple as possible, but not simpler. Albert Einstein