Why does each traverse into the inner arrays as well (tried it with 3 and 4 deep?) Array#length seems to be correct to me and Array#each_index This seems to happen to collect!, and I'd gather other methods as well.
Convenient, if you want depth first traversal on all arrays. but what if you just want to iterate in a shallow manner?
> Why does each traverse into the inner arrays as well (tried it with 3 > and 4 deep?) > Array#length seems to be correct to me and Array#each_index > This seems to happen to collect!, and I'd gather other methods as well.
> Convenient, if you want depth first traversal on all arrays. but what > if you just want to iterate in a shallow manner?
> -----Original Message----- > From: Ed Howland [mailto:ed.howl...@gmail.com] > Sent: Wednesday, October 26, 2005 11:17 AM > To: ruby-talk ML > Subject: Nuby Array questions - each iterates nested arrays?
> Why does each traverse into the inner arrays as well (tried > it with 3 and 4 deep?) Array#length seems to be correct to me > and Array#each_index This seems to happen to collect!, and > I'd gather other methods as well.
Actually, it doesn't. It just looks that way because of the way 'puts' works with arrays. Try 'ruby -e "puts [1,2,3]"' to see what I mean. See the docs on IO.puts for more details.
To see what's really happening replace 'puts' with 'p' (inspect) in your example.
> > Why does each traverse into the inner arrays as well (tried it with 3 > > and 4 deep?) > > Array#length seems to be correct to me and Array#each_index > > This seems to happen to collect!, and I'd gather other methods as well.
> > Convenient, if you want depth first traversal on all arrays. but what > > if you just want to iterate in a shallow manner?