From: Phrogz Date: 2006-12-26T05:35:08+09:00 Subject: Re: Strange about Array#each_index Robert Klemme wrote: > each_index always *returns* the receiver (i.e. the Array or whatever you > invoke that method on) and each_index *passes* every index to the block. A few more examples to help clarify: # Do nothing in the block and see what is returned p %w|a b c|.each_index{ } # => ["a", "b", "c"] # How about the #times method? p 3.times{ } #=> 3 # Apparently it returns the last index passed to the block # Let's write our own def foo; yield; end p foo{ 'a' } #=> 'a' # Our method returns whatever the block returns # Now, let's return something else def foo yield 42 'bar' end p foo{ |x| p x } #=> 42 #=> "bar" That last example is like each_index; it doesn't matter what you do in the block, the method ends up returning a different value from what your block returns.