Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Enumerable#to_h type #462

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/enumerable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
# #=> {1=>1, 2=>4, 3=>9, 4=>16, 5=>25}
# ```
def to_h: () -> ::Hash[untyped, untyped]
| [T, U] () { (Elem) -> [T, U] } -> ::Hash[T, U]

def each_slice: (Integer n) { (::Array[Elem]) -> untyped } -> NilClass
| (Integer n) -> ::Enumerator[::Array[Elem], Return]
Expand Down
14 changes: 14 additions & 0 deletions test/stdlib/Enumerable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ def test_tally
end
end

def test_to_h
enumerable = Class.new {
def each
yield [1, 2]
yield [2, 3]
yield [3, 4]
end

include Enumerable
}.new
enumerable.to_h
enumerable.to_h { |obj| obj }
end

def test_each_entry
enumerable.each_entry
enumerable.each_entry { |x| x }
Expand Down