Skip to content

Commit 7d13d80

Browse files
committed
stdlib: the headers keyword for CSV.foreach can take String
The headers keyword option of `CSV.foreach` can take String, Symbol and Array too. Therefore, this adds them to the type definition. refs: * https://docs.ruby-lang.org/en/3.3/CSV.html#method-c-foreach * https://docs.ruby-lang.org/en/3.3/CSV.html#class-CSV-label-Options+for+Parsing Note: In https://github.com/ruby/rbs/pull/1738/files#r1468802569, @m11o was aware of the lackness of the types, but they determined to support only "true" value at first.
1 parent 2a6c00b commit 7d13d80

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

stdlib/csv/0/csv.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,8 +1722,8 @@ class CSV < Object
17221722
# would read `UTF-32BE` data from the file but transcode it to `UTF-8`
17231723
# before parsing.
17241724
#
1725-
def self.foreach: (String | IO path, ?String mode, headers: true, **untyped options) { (::CSV::Row arg0) -> void } -> void
1726-
| (String | IO path, ?String mode, headers: true, **untyped options) -> Enumerator[::CSV::Row, void]
1725+
def self.foreach: (String | IO path, ?String mode, headers: true | :first_row | Array[untyped] | String, **untyped options) { (::CSV::Row arg0) -> void } -> void
1726+
| (String | IO path, ?String mode, headers: true | :first_row | Array[untyped] | String, **untyped options) -> Enumerator[::CSV::Row, void]
17271727
| (String | IO path, ?String mode, **untyped options) { (::Array[String?] arg0) -> void } -> void
17281728
| (String | IO path, ?String mode, **untyped options) -> Enumerator[::Array[String?], void]
17291729

test/stdlib/CSV_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,23 @@ def test_foreach
2727
CSV, :foreach, path, headers: false, &string_array_block
2828
assert_send_type "(IO path, headers: bool) { (CSV::Row) -> void } -> void",
2929
CSV, :foreach, File.open(path), headers: true, &csv_row_array_block
30+
assert_send_type "(String path, headers: :first_row) { (CSV::Row) -> void } -> void",
31+
CSV, :foreach, path, headers: :first_row, &csv_row_array_block
32+
assert_send_type "(String path, headers: Array[untyped]) { (CSV::Row) -> void } -> void",
33+
CSV, :foreach, path, headers: ["name"], &csv_row_array_block
34+
assert_send_type "(String path, headers: String) { (CSV::Row) -> void } -> void",
35+
CSV, :foreach, path, headers: "name", &csv_row_array_block
3036

3137
assert_send_type "(String path, **untyped) -> Enumerator[Array[String?], void]",
3238
CSV, :foreach, path, encoding: 'UTF-8'
3339
assert_send_type "(String path, headers: bool) -> Enumerator[CSV::Row, void]",
3440
CSV, :foreach, path, headers: true
41+
assert_send_type "(String path, headers: :first_row) -> Enumerator[CSV::Row, void]",
42+
CSV, :foreach, path, headers: :first_row
43+
assert_send_type "(String path, headers: Array[untyped]) -> Enumerator[CSV::Row, void]",
44+
CSV, :foreach, path, headers: ["name"]
45+
assert_send_type "(String path, headers: String) -> Enumerator[CSV::Row, void]",
46+
CSV, :foreach, path, headers: "name"
3547
assert_send_type "(String path, headers: bool, **untyped) -> Enumerator[CSV::Row, void]",
3648
CSV, :foreach, path, headers: true, encoding: 'UTF-8'
3749
end

0 commit comments

Comments
 (0)