Skip to content

Commit 37ebd64

Browse files
committed
Use (...) for delegating instead of (*args) so kwargs and block are passed too
* Core methods regularly gain new keyword arguments so this is more future-proof.
1 parent e4a126d commit 37ebd64

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

lib/pathname.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,20 @@ def inspect # :nodoc:
288288
end
289289

290290
# Return a pathname which is substituted by String#sub.
291-
def sub(pattern, *rest, &block)
291+
def sub(pattern, *args, **kwargs, &block)
292292
if block
293-
path = @path.sub(pattern, *rest) {|*args|
293+
path = @path.sub(pattern, *args, **kwargs) {|*sub_args|
294294
begin
295295
old = Thread.current[:pathname_sub_matchdata]
296296
Thread.current[:pathname_sub_matchdata] = $~
297297
eval("$~ = Thread.current[:pathname_sub_matchdata]", block.binding)
298298
ensure
299299
Thread.current[:pathname_sub_matchdata] = old
300300
end
301-
yield(*args)
301+
yield(*sub_args)
302302
}
303303
else
304-
path = @path.sub(pattern, *rest)
304+
path = @path.sub(pattern, *args, **kwargs)
305305
end
306306
self.class.new(path)
307307
end
@@ -862,17 +862,17 @@ def each_line(...) # :yield: line
862862

863863
# See <tt>IO.read</tt>. Returns all data from the file, or the first +N+ bytes
864864
# if specified.
865-
def read(*args) IO.read(@path, *args) end
865+
def read(...) IO.read(@path, ...) end
866866

867867
# See <tt>IO.binread</tt>. Returns all the bytes from the file, or the first +N+
868868
# if specified.
869-
def binread(*args) IO.binread(@path, *args) end
869+
def binread(...) IO.binread(@path, ...) end
870870

871871
# See <tt>IO.readlines</tt>. Returns all the lines from the file.
872872
def readlines(...) IO.readlines(@path, ...) end
873873

874874
# See <tt>IO.sysopen</tt>.
875-
def sysopen(*args) IO.sysopen(@path, *args) end
875+
def sysopen(...) IO.sysopen(@path, ...) end
876876

877877
# Writes +contents+ to the file. See <tt>File.write</tt>.
878878
def write(...) IO.write(@path, ...) end
@@ -915,10 +915,10 @@ def lchown(owner, group) File.lchown(owner, group, @path) end
915915

916916
# See <tt>File.fnmatch</tt>. Return +true+ if the receiver matches the given
917917
# pattern.
918-
def fnmatch(pattern, *args) File.fnmatch(pattern, @path, *args) end
918+
def fnmatch(pattern, ...) File.fnmatch(pattern, @path, ...) end
919919

920920
# See <tt>File.fnmatch?</tt> (same as #fnmatch).
921-
def fnmatch?(pattern, *args) File.fnmatch?(pattern, @path, *args) end
921+
def fnmatch?(pattern, ...) File.fnmatch?(pattern, @path, ...) end
922922

923923
# See <tt>File.ftype</tt>. Returns "type" of file ("file", "directory",
924924
# etc).
@@ -954,7 +954,7 @@ def truncate(length) File.truncate(@path, length) end
954954
def utime(atime, mtime) File.utime(atime, mtime, @path) end
955955

956956
# See <tt>File.basename</tt>. Returns the last component of the path.
957-
def basename(*args) self.class.new(File.basename(@path, *args)) end
957+
def basename(...) self.class.new(File.basename(@path, ...)) end
958958

959959
# See <tt>File.dirname</tt>. Returns all but the last component of the path.
960960
def dirname() self.class.new(File.dirname(@path)) end
@@ -963,7 +963,7 @@ def dirname() self.class.new(File.dirname(@path)) end
963963
def extname() File.extname(@path) end
964964

965965
# See <tt>File.expand_path</tt>.
966-
def expand_path(*args) self.class.new(File.expand_path(@path, *args)) end
966+
def expand_path(...) self.class.new(File.expand_path(@path, ...)) end
967967

968968
# See <tt>File.split</tt>. Returns the #dirname and the #basename in an
969969
# Array.
@@ -978,7 +978,7 @@ def split()
978978
# Does not contain symlinks or useless dots, +..+ and +.+.
979979
#
980980
# All components of the pathname must exist when this method is called.
981-
def realpath(*args) self.class.new(File.realpath(@path, *args)) end
981+
def realpath(...) self.class.new(File.realpath(@path, ...)) end
982982
end
983983

984984

@@ -1114,7 +1114,7 @@ def each_entry(&block) # :yield: pathname
11141114
end
11151115

11161116
# See <tt>Dir.mkdir</tt>. Create the referenced directory.
1117-
def mkdir(*args) Dir.mkdir(@path, *args) end
1117+
def mkdir(...) Dir.mkdir(@path, ...) end
11181118

11191119
# See <tt>Dir.rmdir</tt>. Remove the referenced directory.
11201120
def rmdir() Dir.rmdir(@path) end

0 commit comments

Comments
 (0)