David A. Black wrote:
> Hi --
>
> On Sat, 31 Jul 2004, Joe Laughlin wrote:
>
>> I have an array that looks like this:
>> my_array = [["Jane", "Smith"], ["Bob", "Jones", 1960]]
>>
>> I want to copy each element of my_array into a another
>> object (in this case, a Gtk::TreeIter).
>>
>> I'm currently doing something like this:
>>
>> tree_store = Gtk::TreeStore.new(String, String, Integer)
>> my_array.each do |person|
>>     count = 0
>>     row = tree_store.append(nil)
>>     person.each do |attribute|
>>       row[count] = attrib
>
> (I think you mean 'attribute' there.)

Doh, I did.

>
>>       count = count + 1
>>     end
>> end
>>
>> So, for each attribute that's in my_array, I want to
>> copy it into the appropriate row element.
>>
>> This works, but how can I do it more cleanly, or more in
>> the ruby spirit?
>
> You could use each_with_index:
>
>   my_array.each do |person|
>     row = tree_store.append(nil)
>     person.each_with_index {|attr,i| row[i] = attr }
>   end

Nice.  Thanks for the tip.

Joe