Skip to content

Commit 6923132

Browse files
hsbtclaude
andcommitted
Refactor Pathname.mktmpdir helpers to class methods
Unify mktmpdir helper methods as private class methods instead of mixing class and instance methods. Inline random_name into make_tmpdir to remove the unnecessary instance method. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d68f08d commit 6923132

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

pathname.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,8 +1433,7 @@ def rmtree
14331433
# end
14341434
#
14351435
def self.mktmpdir
1436-
tmpdir = self.new(resolve_tmpdir)
1437-
path = tmpdir.__send__(:make_tmpdir)
1436+
path = make_tmpdir(resolve_tmpdir)
14381437
if block_given?
14391438
begin
14401439
yield path
@@ -1475,24 +1474,22 @@ def self.resolve_tmpdir
14751474
return systmpdir if File.directory?(systmpdir) && File.writable?(systmpdir)
14761475
'/tmp'
14771476
end
1477+
private_class_method :resolve_tmpdir
14781478

1479-
def make_tmpdir
1479+
def self.make_tmpdir(tmpdir)
14801480
t = Time.now.strftime("%Y%m%d")
14811481
n = nil
14821482
begin
1483-
name = "d#{t}-#{$$}-#{random_name}#{n ? "-#{n}" : ''}"
1484-
path = File.join(@path, name)
1483+
name = "d#{t}-#{$$}-#{Random.urandom(4).unpack1("L").%(36**6).to_s(36)}#{n ? "-#{n}" : ''}"
1484+
path = File.join(tmpdir, name)
14851485
Dir.mkdir(path, 0700)
14861486
rescue Errno::EEXIST
14871487
n = (n || 0) + 1
14881488
retry
14891489
end
1490-
self.class.new(path)
1491-
end
1492-
1493-
def random_name
1494-
Random.urandom(4).unpack1("L").%(36**6).to_s(36)
1490+
new(path)
14951491
end
1492+
private_class_method :make_tmpdir
14961493
end
14971494

14981495
class Pathname

0 commit comments

Comments
 (0)