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

> It would be awesome if #zip could do the same
> with non-nil elements..  (this is what I propose)
>
> p (4..6).zip('a')
> #=> [[4, "a"], [5, "a"], [6, "a"]]
> p (4..6).zip('a', 'b')
> #=> [[4, "a", "b"], [5, "a", "b"], [6, "a", "b"]]
>
> However this is not the way it works at the moment,
> so that behavier would need to be abandoned.
> Which I consider weird and restrictive.. agree?
>
> irb(main):002:0> (4..6).zip('a')
> => [[4, "a"], [5, nil], [6, nil]]
> irb(main):003:0> (4..6).zip('a', 'b')
> => [[4, "a", "b"], [5, nil, nil], [6, nil, nil]]

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...

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)

--Mark



> #zip behaves nice when you pass it an Array.
>
> irb(main):004:0> (4..6).zip(['a', 'b'])
> => [[4, "a"], [5, "b"], [6, nil]]
> irb(main):005:0>
>
>
> BTW: (4..6).zip   #=> [[4], [5], [6]]
> Cool ;-)
>
> --
> Simon Strandgaard
>