Skip to content

Commit 9718271

Browse files
committed
Adjust "wrong element type..." error message for Enumerable#to_h
1 parent e83f780 commit 9718271

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/ruby/truffleruby/core/enumerable.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,13 @@ def to_a(*args, **kwargs)
314314
end
315315
alias_method :entries, :to_a
316316

317-
def to_h(*arg)
317+
def to_h(*args)
318318
h = {}
319-
each_with_index(*arg) do |elem, i|
319+
each(*args) do
320+
elem = Primitive.single_block_arg
320321
elem = yield(elem) if block_given?
321322
unless elem.respond_to?(:to_ary)
322-
raise TypeError, "wrong element type #{Primitive.class(elem)} at #{i} (expected array)"
323+
raise TypeError, "wrong element type #{Primitive.class(elem)} (expected array)"
323324
end
324325

325326
ary = elem.to_ary

0 commit comments

Comments
 (0)