From: Li Chen Date: 2006-12-26T03:51:19+09:00 Subject: Strange about Array#each_index Hi all, Happy holidays! I query Ruby about Array#each_index and here are what Ruby returns: --------------------------------------------------- Array#each_index array.each_index {|index| block } -> array -------------------------------------------------------------------- Same as +Array#each+, but passes the index of the element instead of the element itself. a = [ "a", "b", "c" ] a.each_index {|x| print x, " -- " } produces: 0 -- 1 -- 2 -- According to the above Array#each_index will return only the index for each element: 0,1,2. But when I paste the codes and run on my XP I find Ruby returns both indexes and values. Do I miss something? Thanks, Li ### C:\>irb irb(main):001:0> a = [ "a", "b", "c" ] => ["a", "b", "c"] irb(main):002:0> a.each_index {|x| print x, " -- " } 0 -- 1 -- 2 -- => ["a", "b", "c"] irb(main):003:0> -- Posted via http://www.ruby-forum.com/.