From c137522d7a94107bdeb54aa8b5002297c557228e Mon Sep 17 00:00:00 2001 From: Yuto Urushima Date: Mon, 4 May 2026 16:00:16 +0900 Subject: [PATCH 1/4] Update methods comment --- lib/csv.rb | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/csv.rb b/lib/csv.rb index 89e1a2b..81810f1 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1302,10 +1302,10 @@ def filter(input=nil, output=nil, **options) # # :call-seq: - # foreach(path_or_io, mode='r', **options) {|row| ... ) - # foreach(path_or_io, mode='r', **options) -> new_enumerator + # foreach(filename_or_io, mode='r', **options) {|row| ... ) + # foreach(filename_or_io, mode='r', **options) -> new_enumerator # - # Calls the block with each row read from source +path_or_io+. + # Calls the block with each row read from source +filename_or_io+. # # \Path input without headers: # @@ -1371,7 +1371,7 @@ def filter(input=nil, output=nil, **options) # CSV.foreach(path) # => # # # Arguments: - # * Argument +path_or_io+ must be a file path or an \IO stream. + # * Argument +filename_or_io+ must be a file path or an \IO stream. # * Argument +mode+, if given, must be a \File mode. # See {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes]. # * Arguments **options must be keyword options. @@ -1386,9 +1386,9 @@ def filter(input=nil, output=nil, **options) # encoding: 'UTF-32BE:UTF-8' # would read +UTF-32BE+ data from the file # but transcode it to +UTF-8+ before parsing. - def foreach(path, mode="r", **options, &block) - return to_enum(__method__, path, mode, **options) unless block_given? - open(path, mode, **options) do |csv| + def foreach(filename_or_io, mode="r", **options, &block) + return to_enum(__method__, filename_or_io, mode, **options) unless block_given? + open(filename_or_io, mode, **options) do |csv| csv.each(&block) end end @@ -1565,8 +1565,8 @@ def generate_lines(rows, **options) # # :call-seq: - # open(path_or_io, mode = "rb", **options ) -> new_csv - # open(path_or_io, mode = "rb", **options ) { |csv| ... } -> object + # open(filename_or_io, mode = "rb", **options ) -> new_csv + # open(filename_or_io, mode = "rb", **options ) { |csv| ... } -> object # # possible options elements: # keyword form: @@ -1575,14 +1575,14 @@ def generate_lines(rows, **options) # :undef => :replace # replace undefined conversion # :replace => string # replacement string ("?" or "\uFFFD" if not specified) # - # * Argument +path_or_io+, must be a file path or an \IO stream. + # * Argument +filename_or_io+, must be a file path or an \IO stream. # :include: ../doc/csv/arguments/io.rdoc # * Argument +mode+, if given, must be a \File mode. # See {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes]. # * Arguments **options must be keyword options. # See {Options for Generating}[#class-CSV-label-Options+for+Generating]. # * This method optionally accepts an additional :encoding 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 +filename_or_io+. # You must provide this unless your data is in the encoding # given by Encoding::default_external. # Parsing will use this to determine how to parse the data. @@ -1919,16 +1919,16 @@ def parse_line(line, **options) # path = 't.csv' # File.write(path, string) # CSV.read(path, headers: true) # => # - def read(path, **options) - open(path, **options) { |csv| csv.read } + def read(filename_or_io, **options) + open(filename_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(filename_or_io, **options) + read(filename_or_io, **options) end # :call-seq: @@ -1946,14 +1946,14 @@ def readlines(path, **options) # path = 't.csv' # File.write(path, string) # CSV.table(path) # => # - def table(path, **options) + def table(filename_or_io, **options) default_options = { headers: true, converters: :numeric, header_converters: :symbol, } options = default_options.merge(options) - read(path, **options) + read(filename_or_io, **options) end ON_WINDOWS = /mingw|mswin/.match?(RUBY_PLATFORM) From 703a3c8d3cbcfc0b4e615beae01a99df0dcfff3e Mon Sep 17 00:00:00 2001 From: Yuto Urushima Date: Tue, 5 May 2026 15:29:08 +0900 Subject: [PATCH 2/4] Change filename_or_io to path_or_io --- lib/csv.rb | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/csv.rb b/lib/csv.rb index 81810f1..7b8b4eb 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1302,10 +1302,10 @@ def filter(input=nil, output=nil, **options) # # :call-seq: - # foreach(filename_or_io, mode='r', **options) {|row| ... ) - # foreach(filename_or_io, mode='r', **options) -> new_enumerator + # foreach(path_or_io, mode='r', **options) {|row| ... ) + # foreach(path_or_io, mode='r', **options) -> new_enumerator # - # Calls the block with each row read from source +filename_or_io+. + # Calls the block with each row read from source +path_or_io+. # # \Path input without headers: # @@ -1371,7 +1371,7 @@ def filter(input=nil, output=nil, **options) # CSV.foreach(path) # => # # # Arguments: - # * Argument +filename_or_io+ must be a file path or an \IO stream. + # * Argument +path_or_io+ must be a file path or an \IO stream. # * Argument +mode+, if given, must be a \File mode. # See {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes]. # * Arguments **options must be keyword options. @@ -1386,9 +1386,9 @@ def filter(input=nil, output=nil, **options) # encoding: 'UTF-32BE:UTF-8' # would read +UTF-32BE+ data from the file # but transcode it to +UTF-8+ before parsing. - def foreach(filename_or_io, mode="r", **options, &block) - return to_enum(__method__, filename_or_io, mode, **options) unless block_given? - open(filename_or_io, mode, **options) do |csv| + 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| csv.each(&block) end end @@ -1565,8 +1565,8 @@ def generate_lines(rows, **options) # # :call-seq: - # open(filename_or_io, mode = "rb", **options ) -> new_csv - # open(filename_or_io, mode = "rb", **options ) { |csv| ... } -> object + # open(path_or_io, mode = "rb", **options ) -> new_csv + # open(path_or_io, mode = "rb", **options ) { |csv| ... } -> object # # possible options elements: # keyword form: @@ -1575,14 +1575,14 @@ def generate_lines(rows, **options) # :undef => :replace # replace undefined conversion # :replace => string # replacement string ("?" or "\uFFFD" if not specified) # - # * Argument +filename_or_io+, must be a file path or an \IO stream. + # * Argument +path_or_io+, must be a file path or an \IO stream. # :include: ../doc/csv/arguments/io.rdoc # * Argument +mode+, if given, must be a \File mode. # See {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes]. # * Arguments **options must be keyword options. # See {Options for Generating}[#class-CSV-label-Options+for+Generating]. # * This method optionally accepts an additional :encoding option - # that you can use to specify the Encoding of the data read from +filename_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 # given by Encoding::default_external. # Parsing will use this to determine how to parse the data. @@ -1644,11 +1644,11 @@ def generate_lines(rows, **options) # Raises an exception if the argument is not a \String object or \IO object: # # Raises TypeError (no implicit conversion of Symbol into String) # CSV.open(:foo) - def open(filename_or_io, mode="r", **options) + 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, options, file_opts) @@ -1661,11 +1661,11 @@ def open(filename_or_io, mode="r", **options) options.delete(:replace) options.delete_if {|k, _| /newline\z/.match?(k)} - if filename_or_io.is_a?(StringIO) - f = create_stringio(filename_or_io.string, mode, **file_opts) + if path_or_io.is_a?(StringIO) + f = create_stringio(path_or_io.string, mode, **file_opts) else begin - f = File.open(filename_or_io, mode, **file_opts) + f = File.open(path_or_io, mode, **file_opts) rescue ArgumentError => e raise unless /needs binmode/.match?(e.message) and mode == "r" mode = "rb" @@ -1919,16 +1919,16 @@ def parse_line(line, **options) # path = 't.csv' # File.write(path, string) # CSV.read(path, headers: true) # => # - def read(filename_or_io, **options) - open(filename_or_io, **options) { |csv| csv.read } + 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(filename_or_io, **options) - read(filename_or_io, **options) + def readlines(path_or_io, **options) + read(path_or_io, **options) end # :call-seq: @@ -1946,25 +1946,25 @@ def readlines(filename_or_io, **options) # path = 't.csv' # File.write(path, string) # CSV.table(path) # => # - def table(filename_or_io, **options) + def table(path_or_io, **options) default_options = { headers: true, converters: :numeric, header_converters: :symbol, } options = default_options.merge(options) - read(filename_or_io, **options) + read(path_or_io, **options) end ON_WINDOWS = /mingw|mswin/.match?(RUBY_PLATFORM) private_constant :ON_WINDOWS private - def may_enable_bom_detection_automatically(filename_or_io, + def may_enable_bom_detection_automatically(path_or_io, mode, options, file_opts) - if filename_or_io.is_a?(StringIO) + if path_or_io.is_a?(StringIO) # Support to StringIO was dropped for Ruby 2.6 and earlier without BOM support: # https://github.com/ruby/stringio/pull/47 return if RUBY_VERSION < "2.7" From ead73f42c54c91dced0a6797880d1b2d4904b758 Mon Sep 17 00:00:00 2001 From: Yuto Urushima Date: Wed, 6 May 2026 16:59:45 +0900 Subject: [PATCH 3/4] Change the comment from "+path+ or +io+" to "+path_or_io+" --- lib/csv.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/csv.rb b/lib/csv.rb index 7b8b4eb..80ec5a3 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1377,7 +1377,7 @@ def filter(input=nil, output=nil, **options) # * Arguments **options must be keyword options. # See {Options for Parsing}[#class-CSV-label-Options+for+Parsing]. # * This method optionally accepts an additional :encoding 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 # given by Encoding::default_external. # Parsing will use this to determine how to parse the data. From c646f12fa10c0519d3ba9d309e6adc2588211f99 Mon Sep 17 00:00:00 2001 From: Yuto Urushima Date: Wed, 6 May 2026 17:31:29 +0900 Subject: [PATCH 4/4] Change params source to path_or_io to bring together --- lib/csv.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/csv.rb b/lib/csv.rb index 80ec5a3..3b7fee8 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1901,10 +1901,10 @@ def parse_line(line, **options) # # :call-seq: - # read(source, **options) -> array_of_arrays - # read(source, headers: true, **options) -> csv_table + # read(path_or_io, **options) -> array_of_arrays + # read(path_or_io, headers: true, **options) -> csv_table # - # Opens the given +source+ with the given +options+ (see CSV.open), + # Opens the given +path_or_io+ with the given +options+ (see CSV.open), # reads the source (see CSV#read), and returns the result, # which will be either an \Array of Arrays or a CSV::Table. # @@ -1924,7 +1924,7 @@ def read(path_or_io, **options) end # :call-seq: - # CSV.readlines(source, **options) + # CSV.readlines(path_or_io, **options) # # Alias for CSV.read. def readlines(path_or_io, **options) @@ -1932,9 +1932,9 @@ def readlines(path_or_io, **options) end # :call-seq: - # CSV.table(source, **options) + # CSV.table(path_or_io, **options) # - # Calls CSV.read with +source+, +options+, and certain default options: + # Calls CSV.read with +path_or_io+, +options+, and certain default options: # - +headers+: +true+ # - +converters+: +:numeric+ # - +header_converters+: +:symbol+