From: Logan Capaldo Date: 2006-09-03T06:12:56+09:00 Subject: Re: That's Ruby, Virginia! On Sep 2, 2006, at 4:51 PM, Henry Savr wrote: > Morton Goldberg wrote: >> I don't want to rain on your parade, especially because I can't >> figure out why you're having a parade. I could understand a newbie >> being puzzled about this code (because he wrote [0 ... length] where >> he should used 0 ... length) and posting it so someone could explain >> why it works the way it does, but you say that's not your situation. >> Could you be more explicit about what amuses, delights, intrigues, or >> otherwise motivates you to bring this to our attention? >> >> Regards, Morton > > Well, > I bring it to your attention because: > It mentioned in Programming Ruby, that *for* works with array. They > gave > the example of song array. All languages, which I am familiar with > work > the same way. They > - take an item from Array, > - execute the block, > - and then take another item > > So as [0 ... len] is a new Array, It's a new array of size 1 though. 0...len is a _single_ object what you wrote was x = 0...len for i in [x] Ruby is not perl, ... does not construct lists. > I expected the same behaviour. > But it was not so obvious. It took the whole array and executes the > statement ones. I would expect this behaviour if the code were > > for i = [0 ... len] > > So, my question was to persons, who realy UNDERSTAND Ruby internal > logic, what was it, a bug or undocumented (or may be documented, but I > just missed it) feature? > It's neither a bug or a feature. You just didn't grasp the syntax. > Regards, > Henry > > -- > Posted via http://www.ruby-forum.com/. >