Skip to content

Commit 5891a01

Browse files
[DOC] Doc for ::mkdir (#165)
1 parent de19ccf commit 5891a01

1 file changed

Lines changed: 61 additions & 32 deletions

File tree

lib/fileutils.rb

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -279,38 +279,67 @@ def remove_trailing_slash(dir) #:nodoc:
279279
end
280280
private_module_function :remove_trailing_slash
281281

282-
#
283-
# Creates directories at the paths in the given +list+
284-
# (a single path or an array of paths);
285-
# returns +list+ if it is an array, <tt>[list]</tt> otherwise.
286-
#
287-
# Argument +list+ or its elements
288-
# should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments].
289-
#
290-
# With no keyword arguments, creates a directory at each +path+ in +list+
291-
# by calling: <tt>Dir.mkdir(path, mode)</tt>;
292-
# see {Dir.mkdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-mkdir]:
293-
#
294-
# FileUtils.mkdir(%w[tmp0 tmp1]) # => ["tmp0", "tmp1"]
295-
# FileUtils.mkdir('tmp4') # => ["tmp4"]
296-
#
297-
# Keyword arguments:
298-
#
299-
# - <tt>mode: <i>mode</i></tt> - also calls <tt>File.chmod(mode, path)</tt>;
300-
# see {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod].
301-
# - <tt>noop: true</tt> - does not create directories.
302-
# - <tt>verbose: true</tt> - prints an equivalent command:
303-
#
304-
# FileUtils.mkdir(%w[tmp0 tmp1], verbose: true)
305-
# FileUtils.mkdir(%w[tmp2 tmp3], mode: 0700, verbose: true)
306-
#
307-
# Output:
308-
#
309-
# mkdir tmp0 tmp1
310-
# mkdir -m 700 tmp2 tmp3
311-
#
312-
# Raises an exception if any path points to an existing
313-
# file or directory, or if for any reason a directory cannot be created.
282+
# :markup: markdown
283+
#
284+
# call-seq:
285+
# FileUtils.mkdir(*paths, mode: 0775, noop: nil, verbose: nil) -> array_of_paths or nil
286+
#
287+
# Argument `paths` may be one path or an array of paths;
288+
# each must be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
289+
#
290+
# By default, creates a directory entry at each of the given `paths`;
291+
# each directory has permissions `0775`;
292+
# returns an array of the paths:
293+
#
294+
# ```ruby
295+
# FileUtils.mkdir('foo') # => ["foo"]
296+
# FileUtils.mkdir(%w[bar baz]) # => ["bar", "baz"]
297+
# File.stat(Dir.new('foo')).mode.to_s(8) # => "40775"
298+
# File.stat(Dir.new('bar')).mode.to_s(8) # => "40775"
299+
# File.stat(Dir.new('baz')).mode.to_s(8) # => "40775"
300+
# FileUtils.rmdir(%w[foo bar baz]) # => ["foo", "bar", "baz"]
301+
# ```
302+
#
303+
# Raises an exception if for any reason a directory cannot be created;
304+
# a common reason is that the directory already exists.
305+
#
306+
# With keyword argument `mode` given,
307+
# creates directories with the given permissions:
308+
#
309+
# ```ruby
310+
# FileUtils.mkdir('bar', mode: 0664)
311+
# File.stat(Dir.new('bar')).mode.to_s(8) # => "40664"
312+
# FileUtils.rmdir('bar')
313+
# ```
314+
#
315+
# With keyword argument `noop` given as `true`,
316+
# does not create directories;
317+
# returns `nil`
318+
#
319+
# ```ruby
320+
# FileUtils.mkdir('foo', noop: true) # => nil
321+
# Dir.exist?('foo') # => false
322+
# ```
323+
#
324+
# With keyword argument `verbose` given as `true`,
325+
# prints a shell command:
326+
#
327+
# ```ruby
328+
# FileUtils.mkdir('foo', verbose: true)
329+
# FileUtils.mkdir(%w[bar baz], mode: 0644, verbose: true)
330+
# FileUtils.mkdir(%w[bar baz], mode: 0644, verbose: true, noop: true)
331+
# ```
332+
#
333+
# Output:
334+
#
335+
# ```text
336+
# mkdir foo
337+
# mkdir -m 644 bar baz
338+
# mkdir -m 644 bar baz
339+
# ```
340+
#
341+
# Note that in the last call above (containing `noop: true`)
342+
# the existence of the directory is not checked.
314343
#
315344
# Related: FileUtils.mkdir_p.
316345
#

0 commit comments

Comments
 (0)