From: RichardOnRails Date: 2011-03-01T12:45:22+09:00 Subject: Re: Comining Arrays On Feb 28, 4:46 pm, "David J.Hamilton" wrote: > Excerpts from Paul Sholtz's message of Mon Feb 28 12:31:12 -0800 2011: > > > That is, I'm stepping through one array, and then I'm "counting" to keep > > track of where I am in the other array, so as to "add" the two arrays. > > > I know (before calling the routine) that both arrays are of the same > > size, and that elements of the corresponding arrays will be added > > together. > > Sounds like you want zip. > >   %w( a b c ).zip( 1..3 ).each {|l, d| puts "# l:#{l}, d:#{d}" } >   # l:a, d:1 >   # l:b, d:2 >   # l:c, d:3 >   # => [["a", 1], ["b", 2], ["c", 3]] > > -- > med vänlig hälsning > David J. Hamilton Hey David, Neat code, but I don't get it. %w( a b c ) yields an instance of class String. %w( a b c ).zip( 1..3 ) invokes the ostensible zip method of the String class with a Range instance as an argument. But String has no zip method. So I misunderstand something about writing Ruby. Would you be so kind as to enlighten me. Thanks in Advance, Richard