Forum: Ruby-core [Feature #2946] Apparently inconsistent zip of Range

Posted by Brian Candler (Guest)
on 2010-03-08 14:31
(Received via mailing list)
Feature #2946: Apparently inconsistent zip of Range
http://redmine.ruby-lang.org/issues/show/2946

Author: Brian Candler
Status: Open, Priority: Low

You can zip an Array onto a Range, but not a Range onto an Array.

>> RUBY_DESCRIPTION
=> "ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]"

>> (9..12).zip([1,2,3,4])
=> [[9, 1], [10, 2], [11, 3], [12, 4]]

>> [1,2,3,4].zip(5..8)
TypeError: can't convert Range into Array
  from (irb):6:in `zip'
  from (irb):6
  from :0

Wonder if zip should call #to_a on its argument?

>> (5..8).to_a
=> [5, 6, 7, 8]
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.