On 8/25/06, William James <w_a_x_man / yahoo.com> wrote:
> Henry Savr wrote:
> > Here it is:
> >
> > def array_101
> >   for i in [0 ... self.length]
> >     puts "#{i} => #{self[i]}"
> >   end
> > end
>
> class Array
>   def array_101
>     each_with_index{|e,i|
>       puts "#{i} => #{e}"
>     }
>   end
>   def array_102
>     puts (0...self.size).zip(self).map{|a| a.join(' => ')}
>   end
> end
>

Much better this way.

To fix the original code, use (0..self.length) - note these are not
square brackets. Alternatively, you can use (0..10).to_a to turn a
range into an array.

Max