From: Simon Strandgaard Date: 2004-04-12T21:29:18+09:00 Subject: Re: proposal - zip to do padding On Mon, 12 Apr 2004 17:24:01 +0900, Mark Hubbart wrote: > On Apr 11, 2004, at 6:59 PM, Simon Strandgaard wrote: > >> We already have pad with nils >> >> irb(main):001:0> (4..6).zip(nil) >> => [[4, nil], [5, nil], [6, nil]] > > note that this doesn't work in the current version: > > irb(main):001:0> RUBY_VERSION > => "1.9.0" > irb(main):002:0> (4..6).zip(nil) > TypeError: cannot convert nil into Array > from (irb):2:in `zip' > from (irb):2 > 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> > 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> -- Simon Strandgaard