Skip to content

Commit 684b730

Browse files
authored
Merge pull request #2003 from tk0miya/csv_table_each
stdlib: Add types for CSV::Table#each
2 parents 102d95c + 74aa11b commit 684b730

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

stdlib/csv/0/csv.rbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,7 +3003,7 @@ end
30033003
# table['Name'] # => ["Foo", "Bar", "Baz"]
30043004
#
30053005
class CSV::Table[out Elem] < Object
3006-
include Enumerable[untyped]
3006+
include Enumerable[Elem]
30073007
extend Forwardable
30083008

30093009
# <!--
@@ -3634,8 +3634,8 @@ class CSV::Table[out Elem] < Object
36343634
# Returns a new Enumerator if no block is given:
36353635
# table.each # => #<Enumerator: #<CSV::Table mode:col row_count:4>:each>
36363636
#
3637-
def each: () -> Enumerator[untyped, self]
3638-
| () { (untyped) -> void } -> self
3637+
def each: () -> Enumerator[Elem, self]
3638+
| () { (Elem) -> void } -> self
36393639
| () { (*untyped) -> void } -> self
36403640

36413641
def empty?: (*untyped args) { (*untyped) -> untyped } -> untyped

test/stdlib/CSV_Table_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "test_helper"
4+
require "csv"
5+
6+
class CSV::TableInstanceTest < Test::Unit::TestCase
7+
include TestHelper
8+
9+
library 'csv'
10+
testing "CSV::Table[CSV::Row]"
11+
12+
def test_each
13+
table = CSV::Table.new([
14+
CSV::Row.new([], []),
15+
CSV::Row.new([], []),
16+
CSV::Row.new([], [])
17+
])
18+
19+
assert_send_type "() -> Enumerator[CSV::Row, void]",
20+
table, :each
21+
assert_send_type "() { (CSV::Row) -> void } -> CSV::Table",
22+
table, :each do end
23+
end
24+
end

0 commit comments

Comments
 (0)