mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Should raise TypeError instead of NoMethodError
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user