From: Mark Hubbart Date: 2004-04-13T06:47:38+09:00 Subject: Re: proposal - zip to do padding On Apr 12, 2004, at 5:29 AM, Simon Strandgaard wrote: > I also use 1.9.. but gets different result. > What date does your 'ruby -v' tell? > > server> ruby -v > ruby 1.9.0 (2004-04-06) [i386-freebsd5.1] > server> irb > irb(main):001:0> (4..6).zip(nil) > => [[4, nil], [5, nil], [6, nil]] > irb(main):002:0> okay, I guess that particular release (2004-02-21) of 1.9 was flawed :) I got the latest snapshot and the error went away. #to_a was not implemented for nil in that release. However, now (4..6).zip(1) doesn't work, since Fixnum#to_a is not implemented. hmmm... I remember a warning on 1.8, I believe, hat stated that Object#to_a was being deprecated, and may be removed in future versions. Perhaps this is the result? >> Maybe are missing the point of what zip does... when you call #zip, it >> ensures the object you pass to it is an array; then it zips it. I'm >> guessing #zip calls to_a on it... >> > > What you described is the behavier of Ruby-1.8.1. > > I should have mentioned that I am using 1.9 > server> ruby -v > ruby 1.9.0 (2004-04-06) [i386-freebsd5.1] > server> > > >> But I may be misunderstanding your proposal... Isn't what you are >> proposing something like this? >> >> irb(main):003:0> (4..6).map{|i|[i,'a']} >> => [[4, "a"], [5, "a"], [6, "a"]] >> >> (as was suggested by daz elsewhere in the thread) > > No, thats the subject of another thread.. > that is not what my proposal is about. > > > My proposal is about changing the current behavier of 1.9, > so that it does padding, rather than placing all the > supplied arguments to the first element only. > > The current behavier > irb(main):001:0> (4..6).zip('a') > => [[4, "a"], [5, nil], [6, nil]] > irb(main):002:0> (4..6).zip('a', 'b') > => [[4, "a", "b"], [5, nil, nil], [6, nil, nil]] > irb(main):003:0> > > Proposed behavier > irb(main):001:0> (4..6).zip('a') > => [[4, "a"], [5, "a"], [6, "a"]] > irb(main):002:0> (4..6).zip('a', 'b') > => [[4, "a", "b"], [5, "a", "b"], [6, "a", "b"]] > irb(main):003:0> As pointed out by someone else, how should we determine when to pad with an object, and when to zip? Only zip if the object implements #to_ary? or #each? or, perhaps, #next? Perhaps if you would post some code it would clear this up, so that it would be obvious what the behavior would be. Note that I'm not against it; I just want to know how it would work. If you can get it to work intuitively, then I would be all for it. :) --Mark