-
Notifications
You must be signed in to change notification settings - Fork 216
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 type for CSV.foreach #1738
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1722,7 +1722,10 @@ class CSV < Object | |
# would read `UTF-32BE` data from the file but transcode it to `UTF-8` | ||
# before parsing. | ||
# | ||
def self.foreach: [U] (String | IO | StringIO path, ?::Hash[Symbol, U] options) { (::Array[String?] arg0) -> void } -> void | ||
def self.foreach: (String | IO path, ?String mode, headers: true, **untyped options) { (::CSV::Row arg0) -> void } -> void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accurately, the However, As headers argument is often provided true, I defined true only in this methods. |
||
| (String | IO path, ?String mode, headers: true, **untyped options) -> Enumerator[::CSV::Row, void] | ||
| (String | IO path, ?String mode, **untyped options) { (::Array[String?] arg0) -> void } -> void | ||
| (String | IO path, ?String mode, **untyped options) -> Enumerator[::Array[String?], void] | ||
|
||
# <!-- | ||
# rdoc-file=lib/csv.rb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "test_helper" | ||
require "csv" | ||
|
||
class CSVSingletonTest < Test::Unit::TestCase | ||
include TestHelper | ||
|
||
library 'csv' | ||
testing "singleton(::CSV)" | ||
|
||
def test_foreach | ||
tmpdir = Dir.mktmpdir | ||
path = File.join(tmpdir, "example.csv") | ||
File.write(path, "a,b,c\n1,2,3\n") | ||
|
||
string_array_block = ->(row) { row.size } | ||
assert_send_type "(String path) { (Array[String?]) -> void } -> void", | ||
CSV, :foreach, path, &string_array_block | ||
assert_send_type "(IO path) { (Array[String?]) -> void } -> void", | ||
CSV, :foreach, File.open(path), &string_array_block | ||
|
||
csv_row_array_block = ->(row) { row.fields } | ||
assert_send_type "(String path, headers: true) { (CSV::Row) -> void } -> void", | ||
CSV, :foreach, path, headers: true, &csv_row_array_block | ||
assert_send_type "(String path, headers: false) { (Array[String?]) -> void } -> void", | ||
CSV, :foreach, path, headers: false, &string_array_block | ||
assert_send_type "(IO path, headers: bool) { (CSV::Row) -> void } -> void", | ||
CSV, :foreach, File.open(path), headers: true, &csv_row_array_block | ||
|
||
assert_send_type "(String path, **untyped) -> Enumerator[Array[String?], void]", | ||
CSV, :foreach, path, encoding: 'UTF-8' | ||
assert_send_type "(String path, headers: bool) -> Enumerator[CSV::Row, void]", | ||
CSV, :foreach, path, headers: true | ||
assert_send_type "(String path, headers: bool, **untyped) -> Enumerator[CSV::Row, void]", | ||
CSV, :foreach, path, headers: true, encoding: 'UTF-8' | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add csv gem to Gemfile because it is changed from default gem to bundled gem in ruby 3.4.
ref: #1734