Unverified Commit b1c8fad9 authored by ksss's avatar ksss

Should raise TypeError instead of NoMethodError

parent 5a7ce01f
......@@ -768,7 +768,12 @@ module Enumerable
def zip(*arg, &block)
result = block ? nil : []
arg = arg.map{|a|a.to_a}
arg = arg.map do |a|
unless a.respond_to?(:to_a)
raise TypeError, "wrong argument type #{a.class} (must respond to :to_a)"
end
a.to_a
end
i = 0
self.each do |*val|
......
......@@ -170,6 +170,8 @@ assert("Enumerable#zip") do
ret = []
assert_equal nil, a.zip([1, 2], [8]) { |i| ret << i }
assert_equal [[4, 1, 8], [5, 2, nil], [6, nil, nil]], ret
assert_raise(TypeError) { [1].zip(1) }
end
assert("Enumerable#to_h") do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment