From: Yossef Mendelssohn Date: 2007-10-25T11:58:34+09:00 Subject: Re: Intervals in Ruby On Oct 24, 8:45 pm, Steven D'Aprano wrote: > I understand that in Ruby you have quite a few choices, some of which are > half-open like Python, some of which are closed: > > 0..5 => 0, 1, 2, 3, 4, 5 > 0...5 => 0, 1, 2, 3, 4 > > 5.downto(1) => 5, 4, 3, 2, 1 > 1.upto(5) => 1, 2, 3, 4, 5 > 5.times() => 0, 1, 2, 3, 4 > 5.step(11, 3) => 5, 8, 11 > > and the Range.new method. > > My question is: how useful are all these different mechanisms? Do you > find that having two operators .. and ... is a blessing, or a curse > because you can never remember which is which? I can only speak from my own experience. I came to Ruby from Perl, so I knew .. and ... backwards and forwards. There might have been a bit of a stumbling block when I was learning Perl, but it's been so long that it all seems natural to me. And speaking of Perl and "natural", much of that has to do with the language's creator/designer being a linguist (or at least people like to say so). When I came to Ruby, it felt like Matz took up that cause and ran with it. For many problems, there are many, many solutions. You choose which one works for you. Methods like Integer#times, Integer#downto, Integer#upto, Numeric#step all have their uses. Choosing the right one feels like choosing the right word to construct a sentence. -- -yossef