Skip to content

Commit

Permalink
Merge pull request #2012 from euglena1215/csv-headers
Browse files Browse the repository at this point in the history
stdlib: Add types for CSV#headers
  • Loading branch information
soutaro committed Sep 17, 2024
2 parents 6294660 + 0f44c99 commit a9ae829
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions stdlib/csv/0/csv.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,16 @@ class CSV < Object
#
def each: () -> Enumerator[untyped, Integer]
| () { (untyped) -> void } -> Integer

# <!--
# rdoc-file=lib/csv.rb
# - csv.headers -> object
# -->
# Returns the value that determines whether headers are used; used for parsing;
# see {Option `headers`[}](#class-CSV-label-Option+headers):
# CSV.new('').headers # => nil
#
def headers: () -> (Array[String] | true | nil)
end

# <!-- rdoc-file=lib/csv.rb -->
Expand Down
20 changes: 20 additions & 0 deletions test/stdlib/CSV_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,23 @@ def test_read
CSV, :read, File.open(path)
end
end

class CSVTest < Test::Unit::TestCase
include TestHelper

library "csv"
testing "CSV"

def test_headers
csv = CSV.new("header1,header2\nrow1_1,row1_2")
assert_send_type "() -> nil",
csv, :headers

csv = CSV.new("header1,header2\nrow1_1,row1_2", headers: true)
assert_send_type "() -> true",
csv, :headers
csv.read
assert_send_type "() -> Array[String]",
csv, :headers
end
end

0 comments on commit a9ae829

Please sign in to comment.