Stefano Crocco
4/7/2008 11:41:00 AM
On Monday 07 April 2008, Pan Kracy wrote:
> I don't use "lines.each do |line|" because I need number of line.
Do you know about Array#each_index and Array#each_with_index?:
['a', 'b', 'c'].each_index{|i| puts i}
Output:
0
1
2
['a', 'b', 'c'].each_with_index{|obj, i| puts "i: #{i}, obj: #{obj}"}
Output:
i: 0, obj: a
i: 1, obj: b
i: 2, obj: c
Stefano