Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.
For all of you actionscripters out there, this example is the Ruby equivalent of writing for(i in array){trace(i);} or for(i = 0; i < array.length; i++){trace(i);}
With the names array already initialized, a more idiomatic iteration would be:
names.eachwithindex { |name, i| puts "#{i} #{name}" }
That would be:
names.each_with_index { |name, i| puts "#{i} #{name}" }Thanks for the tip ed!