instance method
Pathname#mkpath
() -> self
mkpath(mode: nil)
pathname_builtin.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/pathname_builtin.rb, line 334
def mkpath(mode: nil)
path = @path == '/' ? @path : @path.chomp('/')
stack = []
until File.directory?(path) || File.dirname(path) == path
stack.push path
path = File.dirname(path)
end
stack.reverse_each do |dir|
dir = dir == '/' ? dir : dir.chomp('/')
if mode
Dir.mkdir dir, mode
File.chmod mode, dir
else
Dir.mkdir dir
end
rescue SystemCallError
raise unless File.directory?(dir)
end
self
end
Creates a full path, including any intermediate directories that don’t yet exist.
See FileUtils.mkpath and FileUtils.mkdir_p