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

stdlib: Add types for CSV::Table#each #2003

Merged
merged 1 commit into from
Sep 13, 2024
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
6 changes: 3 additions & 3 deletions stdlib/csv/0/csv.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,7 @@ end
# table['Name'] # => ["Foo", "Bar", "Baz"]
#
class CSV::Table[out Elem] < Object
include Enumerable[untyped]
include Enumerable[Elem]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change correct? If my understanding is correct, Elem means a row of the table. So #each and Enumerable should use Elem, right?

extend Forwardable

# <!--
Expand Down Expand Up @@ -3633,8 +3633,8 @@ class CSV::Table[out Elem] < Object
# Returns a new Enumerator if no block is given:
# table.each # => #<Enumerator: #<CSV::Table mode:col row_count:4>:each>
#
def each: () -> Enumerator[untyped, self]
| () { (untyped) -> void } -> self
def each: () -> Enumerator[Elem, self]
| () { (Elem) -> void } -> self
| () { (*untyped) -> void } -> self

def empty?: (*untyped args) { (*untyped) -> untyped } -> untyped
Expand Down
24 changes: 24 additions & 0 deletions test/stdlib/CSV_Table_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require_relative "test_helper"
require "csv"

class CSV::TableInstanceTest < Test::Unit::TestCase
include TestHelper

library 'csv'
testing "CSV::Table[CSV::Row]"

def test_each
table = CSV::Table.new([
CSV::Row.new([], []),
CSV::Row.new([], []),
CSV::Row.new([], [])
])

assert_send_type "() -> Enumerator[CSV::Row, void]",
table, :each
assert_send_type "() { (CSV::Row) -> void } -> CSV::Table",
table, :each do end
end
end