Unify first parameter name to path_or_io across methods#358
Unify first parameter name to path_or_io across methods#358alstrocrack wants to merge 4 commits intoruby:mainfrom
path_or_io across methods#358Conversation
filename_or_io across methods
|
Hmm. Let's use |
|
Thank you for your suggestion. |
|
Could you also update the PR title and description? |
There was a problem hiding this comment.
Pull request overview
This PR aims to standardize the first parameter name across CSV class methods to better communicate that callers may pass either a file path or an IO-like object, and to align the corresponding RDoc wording.
Changes:
- Renames the first parameter for
CSV.foreach,CSV.read,CSV.readlines, andCSV.tableto a unified name. - Renames
CSV.open’s first parameter and the related private helper parameter to match the unified name. - Updates related RDoc text to reference the unified parameter name.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def foreach(path_or_io, mode="r", **options, &block) | ||
| return to_enum(__method__, path_or_io, mode, **options) unless block_given? | ||
| open(path_or_io, mode, **options) do |csv| |
| def open(path_or_io, mode="r", **options) | ||
| # wrap a File opened with the remaining +args+ with no newline | ||
| # decorator | ||
| file_opts = {} | ||
| may_enable_bom_detection_automatically(filename_or_io, | ||
| may_enable_bom_detection_automatically(path_or_io, | ||
| mode, |
| def read(path_or_io, **options) | ||
| open(path_or_io, **options) { |csv| csv.read } | ||
| end | ||
|
|
||
| # :call-seq: | ||
| # CSV.readlines(source, **options) | ||
| # | ||
| # Alias for CSV.read. | ||
| def readlines(path, **options) | ||
| read(path, **options) | ||
| def readlines(path_or_io, **options) | ||
| read(path_or_io, **options) |
| def table(path_or_io, **options) | ||
| default_options = { | ||
| headers: true, | ||
| converters: :numeric, | ||
| header_converters: :symbol, | ||
| } | ||
| options = default_options.merge(options) | ||
| read(path, **options) | ||
| read(path_or_io, **options) |
filename_or_io across methodspath_or_io across methods
| def foreach(path_or_io, mode="r", **options, &block) | ||
| return to_enum(__method__, path_or_io, mode, **options) unless block_given? | ||
| open(path_or_io, mode, **options) do |csv| |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
lib/csv.rb:1940
- The
:call-seq:fortablestill usessourcewhile the method signature is nowtable(path_or_io, **options). Since the PR’s goal is to unify the first parameter name, the:call-seq:should also be updated topath_or_ioto keep docs consistent.
# :call-seq:
# CSV.table(source, **options)
#
# Calls CSV.read with +source+, +options+, and certain default options:
# - +headers+: +true+
# - +converters+: +:numeric+
# - +header_converters+: +:symbol+
| # * This method optionally accepts an additional <tt>:encoding</tt> option | ||
| # that you can use to specify the Encoding of the data read from +path+ or +io+. | ||
| # that you can use to specify the Encoding of the data read from +path_or_io+. | ||
| # You must provide this unless your data is in the encoding |
There was a problem hiding this comment.
I also think this should be fixed, but it shouldn’t be done in this PR.
| # CSV.read(path, headers: true) # => #<CSV::Table mode:col_or_row row_count:4> | ||
| def read(path, **options) | ||
| open(path, **options) { |csv| csv.read } | ||
| def read(path_or_io, **options) | ||
| open(path_or_io, **options) { |csv| csv.read } |
| # CSV.readlines(source, **options) | ||
| # | ||
| # Alias for CSV.read. | ||
| def readlines(path, **options) | ||
| read(path, **options) | ||
| def readlines(path_or_io, **options) | ||
| read(path_or_io, **options) |
|
I fixed this PR’s title, description, and all the suggestions from GitHub Copilot. Could you please check it again? |
Overview
Previously, the first parameter name was inconsistent across methods and their RDoc comments, with names such as
path,source, andfilename_or_ioused interchangeably despite referring to the same concept:a file path or an IO object.
This change aligns all class methods to use
path_or_io. This more accurately conveys that the argument accepts either a file path or an IO object.Reference