Fix keyword argument separation issues in lib

Mostly requires adding ** in either calls or method definitions.
This commit is contained in:
Jeremy Evans 2019-04-07 16:44:49 -07:00
parent 3f67fcd3d5
commit d08e1004e0
Notes: git 2019-08-31 04:40:18 +09:00
13 changed files with 38 additions and 38 deletions

View File

@ -432,7 +432,7 @@ class CSV
# fetch or create the instance for this signature # fetch or create the instance for this signature
@@instances ||= Hash.new @@instances ||= Hash.new
instance = (@@instances[sig] ||= new(data, options)) instance = (@@instances[sig] ||= new(data, **options))
if block_given? if block_given?
yield instance # run block, if given, returning result yield instance # run block, if given, returning result
@ -480,8 +480,8 @@ class CSV
end end
end end
# build input and output wrappers # build input and output wrappers
input = new(input || ARGF, in_options) input = new(input || ARGF, **in_options)
output = new(output || $stdout, out_options) output = new(output || $stdout, **out_options)
# read, yield, write # read, yield, write
input.each do |row| input.each do |row|
@ -505,8 +505,8 @@ class CSV
# but transcode it to UTF-8 before CSV parses it. # but transcode it to UTF-8 before CSV parses it.
# #
def self.foreach(path, mode="r", **options, &block) def self.foreach(path, mode="r", **options, &block)
return to_enum(__method__, path, mode, options) unless block_given? return to_enum(__method__, path, mode, **options) unless block_given?
open(path, mode, options) do |csv| open(path, mode, **options) do |csv|
csv.each(&block) csv.each(&block)
end end
end end
@ -539,7 +539,7 @@ class CSV
str = +"" str = +""
str.force_encoding(encoding) if encoding str.force_encoding(encoding) if encoding
end end
csv = new(str, options) # wrap csv = new(str, **options) # wrap
yield csv # yield for appending yield csv # yield for appending
csv.string # return final String csv.string # return final String
end end
@ -565,7 +565,7 @@ class CSV
elsif field = row.find {|f| f.is_a?(String)} elsif field = row.find {|f| f.is_a?(String)}
str.force_encoding(field.encoding) str.force_encoding(field.encoding)
end end
(new(str, options) << row).string (new(str, **options) << row).string
end end
# #
@ -645,7 +645,7 @@ class CSV
retry retry
end end
begin begin
csv = new(f, options) csv = new(f, **options)
rescue Exception rescue Exception
f.close f.close
raise raise
@ -675,8 +675,8 @@ class CSV
# You pass your +str+ to read from, and an optional +options+ containing # You pass your +str+ to read from, and an optional +options+ containing
# anything CSV::new() understands. # anything CSV::new() understands.
# #
def self.parse(*args, &block) def self.parse(*args, **options, &block)
csv = new(*args) csv = new(*args, **options)
return csv.each(&block) if block_given? return csv.each(&block) if block_given?
@ -696,7 +696,7 @@ class CSV
# The +options+ parameter can be anything CSV::new() understands. # The +options+ parameter can be anything CSV::new() understands.
# #
def self.parse_line(line, **options) def self.parse_line(line, **options)
new(line, options).shift new(line, **options).shift
end end
# #
@ -710,13 +710,13 @@ class CSV
# <tt>encoding: "UTF-32BE:UTF-8"</tt> would read UTF-32BE data from the file # <tt>encoding: "UTF-32BE:UTF-8"</tt> would read UTF-32BE data from the file
# but transcode it to UTF-8 before CSV parses it. # but transcode it to UTF-8 before CSV parses it.
# #
def self.read(path, *options) def self.read(*args, **options)
open(path, *options) { |csv| csv.read } open(*args, **options) { |csv| csv.read }
end end
# Alias for CSV::read(). # Alias for CSV::read().
def self.readlines(*args) def self.readlines(*args, **options)
read(*args) read(*args, **options)
end end
# #
@ -727,9 +727,9 @@ class CSV
# header_converters: :symbol }.merge(options) ) # header_converters: :symbol }.merge(options) )
# #
def self.table(path, **options) def self.table(path, **options)
read( path, { headers: true, read( path, **{ headers: true,
converters: :numeric, converters: :numeric,
header_converters: :symbol }.merge(options) ) header_converters: :symbol }.merge(options) )
end end
# #

View File

@ -4,6 +4,6 @@ class Array # :nodoc:
# ["CSV", "data"].to_csv # ["CSV", "data"].to_csv
# #=> "CSV,data\n" # #=> "CSV,data\n"
def to_csv(**options) def to_csv(**options)
CSV.generate_line(self, options) CSV.generate_line(self, **options)
end end
end end

View File

@ -4,6 +4,6 @@ class String # :nodoc:
# "CSV,data".parse_csv # "CSV,data".parse_csv
# #=> ["CSV", "data"] # #=> ["CSV", "data"]
def parse_csv(**options) def parse_csv(**options)
CSV.parse_line(self, options) CSV.parse_line(self, **options)
end end
end end

View File

@ -345,7 +345,7 @@ class CSV
# csv_row.fields.to_csv( options ) # csv_row.fields.to_csv( options )
# #
def to_csv(**options) def to_csv(**options)
fields.to_csv(options) fields.to_csv(**options)
end end
alias_method :to_s, :to_csv alias_method :to_s, :to_csv

View File

@ -367,9 +367,9 @@ class CSV
# pass <tt>:write_headers => false</tt>. # pass <tt>:write_headers => false</tt>.
# #
def to_csv(write_headers: true, **options) def to_csv(write_headers: true, **options)
array = write_headers ? [headers.to_csv(options)] : [] array = write_headers ? [headers.to_csv(**options)] : []
@table.each do |row| @table.each do |row|
array.push(row.fields.to_csv(options)) unless row.header_row? array.push(row.fields.to_csv(**options)) unless row.header_row?
end end
array.join("") array.join("")

View File

@ -1456,7 +1456,7 @@ module Net
if defined?(OpenSSL::SSL::SSLSocket) if defined?(OpenSSL::SSL::SSLSocket)
class BufferedSSLSocket < BufferedSocket class BufferedSSLSocket < BufferedSocket
def initialize(*args) def initialize(*args, **options)
super super
@is_shutdown = false @is_shutdown = false
end end

View File

@ -322,7 +322,7 @@ module Net # :nodoc:
class InternetMessageIO < BufferedIO #:nodoc: internal use only class InternetMessageIO < BufferedIO #:nodoc: internal use only
def initialize(*) def initialize(*, **)
super super
@wbuf = nil @wbuf = nil
end end

View File

@ -269,7 +269,7 @@ class RDoc::Generator::Darkfish
@options.static_path.each do |path| @options.static_path.each do |path|
unless File.directory? path then unless File.directory? path then
FileUtils.install path, @outputdir, fu_options.merge(:mode => 0644) FileUtils.install path, @outputdir, **fu_options.merge(:mode => 0644)
next next
end end
@ -278,9 +278,9 @@ class RDoc::Generator::Darkfish
dest_file = @outputdir + entry dest_file = @outputdir + entry
if File.directory? entry then if File.directory? entry then
FileUtils.mkdir_p entry, fu_options FileUtils.mkdir_p entry, **fu_options
else else
FileUtils.install entry, dest_file, fu_options.merge(:mode => 0644) FileUtils.install entry, dest_file, **fu_options.merge(:mode => 0644)
end end
end end
end end
@ -585,16 +585,16 @@ class RDoc::Generator::Darkfish
return unless source.exist? return unless source.exist?
begin begin
FileUtils.mkdir_p File.dirname(destination), options FileUtils.mkdir_p File.dirname(destination), **options
begin begin
FileUtils.ln source, destination, options FileUtils.ln source, destination, **options
rescue Errno::EEXIST rescue Errno::EEXIST
FileUtils.rm destination FileUtils.rm destination
retry retry
end end
rescue rescue
FileUtils.cp source, destination, options FileUtils.cp source, destination, **options
end end
end end

View File

@ -469,7 +469,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
subdirs.each do |name| subdirs.each do |name|
subdir = File.join dir, name subdir = File.join dir, name
next if File.exist? subdir next if File.exist? subdir
FileUtils.mkdir_p subdir, options rescue nil FileUtils.mkdir_p subdir, **options rescue nil
end end
ensure ensure
File.umask old_umask File.umask old_umask

View File

@ -129,7 +129,7 @@ By default, this RubyGems will install gem as:
end end
module MakeDirs module MakeDirs
def mkdir_p(path, *opts) def mkdir_p(path, **opts)
super super
(@mkdirs ||= []) << path (@mkdirs ||= []) << path
end end

View File

@ -513,7 +513,7 @@ EOM
path = File.expand_path(path + File::SEPARATOR + basename) path = File.expand_path(path + File::SEPARATOR + basename)
lstat = File.lstat path rescue nil lstat = File.lstat path rescue nil
if !lstat || !lstat.directory? if !lstat || !lstat.directory?
unless normalize_path(path).start_with? normalize_path(destination_dir) and (FileUtils.mkdir path, mkdir_options rescue false) unless normalize_path(path).start_with? normalize_path(destination_dir) and (FileUtils.mkdir path, **mkdir_options rescue false)
raise Gem::Package::PathError.new(file_name, destination_dir) raise Gem::Package::PathError.new(file_name, destination_dir)
end end
end end

View File

@ -128,7 +128,7 @@ class Tempfile < DelegateClass(File)
@unlinked = false @unlinked = false
@mode = mode|File::RDWR|File::CREAT|File::EXCL @mode = mode|File::RDWR|File::CREAT|File::EXCL
::Dir::Tmpname.create(basename, tmpdir, options) do |tmpname, n, opts| ::Dir::Tmpname.create(basename, tmpdir, **options) do |tmpname, n, opts|
opts[:perm] = 0600 opts[:perm] = 0600
@tmpfile = File.open(tmpname, @mode, opts) @tmpfile = File.open(tmpname, @mode, opts)
@opts = opts.freeze @opts = opts.freeze
@ -326,7 +326,7 @@ end
# #
def Tempfile.create(basename="", tmpdir=nil, mode: 0, **options) def Tempfile.create(basename="", tmpdir=nil, mode: 0, **options)
tmpfile = nil tmpfile = nil
Dir::Tmpname.create(basename, tmpdir, options) do |tmpname, n, opts| Dir::Tmpname.create(basename, tmpdir, **options) do |tmpname, n, opts|
mode |= File::RDWR|File::CREAT|File::EXCL mode |= File::RDWR|File::CREAT|File::EXCL
opts[:perm] = 0600 opts[:perm] = 0600
tmpfile = File.open(tmpname, mode, opts) tmpfile = File.open(tmpname, mode, opts)

View File

@ -82,9 +82,9 @@ class Dir
# FileUtils.remove_entry dir # FileUtils.remove_entry dir
# end # end
# #
def self.mktmpdir(prefix_suffix=nil, *rest) def self.mktmpdir(prefix_suffix=nil, *rest, **options)
base = nil base = nil
path = Tmpname.create(prefix_suffix || "d", *rest) {|path, _, _, d| path = Tmpname.create(prefix_suffix || "d", *rest, **options) {|path, _, _, d|
base = d base = d
mkdir(path, 0700) mkdir(path, 0700)
} }