From: James Edward Gray II Date: 2007-10-26T02:36:59+09:00 Subject: Re: Intervals in Ruby On Oct 25, 2007, at 12:28 PM, Joel VanderWerf wrote: > James Edward Gray II wrote: >> On Oct 25, 2007, at 1:40 AM, Robert Klemme wrote: >>> Both range versions come in handy, for example, if you need to >>> iterate through an array using an index counter then the triple >>> dot is convenient because you do not need to to math: >>> >>> for i in 0...ar.size >>> puts ar[i] >>> end >>> >>> #times is an alternative here >>> >>> ar.size.times do |i| >>> puts ar[i] >>> end >> >> letters = (0..9).map { |i| (?a + i).chr } >> => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] >> >> letters.each_index do |i| >> ?> puts letters[i] >> >> end >> a >> b >> c >> d >> e >> f >> g >> h >> i >> j >> => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] > > What was that example meant to show? Must be something other than > this: > > puts ("a".."j").to_a Yeah, that was dumb of me. That wasn't the point though. I was showing each_index() which was recreated above in two different ways. James Edward Gray II