Skip to content

Commit a0ea474

Browse files
committed
Enhanced RDoc for FileUtils
1 parent c38fd02 commit a0ea474

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

lib/fileutils.rb

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,35 @@ def mkdir(list, mode: nil, noop: nil, verbose: nil)
236236
module_function :mkdir
237237

238238
#
239-
# Creates a directory and all its parent directories.
240-
# For example,
239+
# Creates directories at the paths in the given +list+
240+
# (an array of strings or a single string),
241+
# also creating ancestor directories as needed;
242+
# returns +list+.
243+
#
244+
# With no keyword arguments, creates a directory at each +path+ in +list+,
245+
# along with any needed ancestor directories,
246+
# by calling: <tt>Dir.mkdir(path, mode)</tt>;
247+
# see {Dir.mkdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-mkdir]:
248+
#
249+
# FileUtils.mkdir_p(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"]
250+
# FileUtils.mkdir_p('tmp4/tmp5') # => ["tmp4/tmp5"]
251+
#
252+
# Keyword arguments:
253+
#
254+
# - <tt>mode: <i>integer</i></tt> - also calls <tt>File.chmod(mode, path)</tt>;
255+
# see {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod].
256+
# - <tt>noop: true</tt> - does not create directories.
257+
# - <tt>verbose: true</tt> - prints an equivalent command:
241258
#
242-
# FileUtils.mkdir_p '/usr/local/lib/ruby'
259+
# FileUtils.mkdir_p(%w[tmp0 tmp1], verbose: true)
260+
# FileUtils.mkdir_p(%w[tmp2 tmp3], mode: 0700, verbose: true)
243261
#
244-
# causes to make following directories, if they do not exist.
262+
# Output:
245263
#
246-
# * /usr
247-
# * /usr/local
248-
# * /usr/local/lib
249-
# * /usr/local/lib/ruby
264+
# mkdir -p tmp0 tmp1
265+
# mkdir -p -m 700 tmp2 tmp3
250266
#
251-
# You can pass several directories at a time in a list.
267+
# Raises an exception if for any reason a directory cannot be created.
252268
#
253269
def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
254270
list = fu_list(list)
@@ -293,12 +309,34 @@ def fu_mkdir(path, mode) #:nodoc:
293309
private_module_function :fu_mkdir
294310

295311
#
296-
# Removes one or more directories.
312+
# Removes directories at the paths in the given +list+
313+
# (an array of strings or a single string);
314+
# returns +list+.
315+
#
316+
# With no keyword arguments, removes the directory at each +path+ in +list+,
317+
# by calling: <tt>Dir.rmdir(path, mode)</tt>;
318+
# see {Dir.rmdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-rmdir]:
319+
#
320+
# FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3]) # => ["tmp0/tmp1", "tmp2/tmp3"]
321+
# FileUtils.rmdir('tmp4/tmp5') # => ["tmp4/tmp5"]
322+
#
323+
# Keyword arguments:
324+
#
325+
# - <tt>parents: true</tt> - removes successive ancestor directories
326+
# if empty.
327+
# - <tt>noop: true</tt> - does not remove directories.
328+
# - <tt>verbose: true</tt> - prints an equivalent command:
329+
#
330+
# FileUtils.rmdir(%w[tmp0/tmp1 tmp2/tmp3], parents: true, verbose: true)
331+
# FileUtils.rmdir('tmp4/tmp5', parents: true, verbose: true)
332+
#
333+
# Output:
334+
#
335+
# rmdir -p tmp0/tmp1 tmp2/tmp3
336+
# rmdir -p tmp4/tmp5
297337
#
298-
# FileUtils.rmdir 'somedir'
299-
# FileUtils.rmdir %w(somedir anydir otherdir)
300-
# # Does not really remove directory; outputs message.
301-
# FileUtils.rmdir 'somedir', verbose: true, noop: true
338+
# Raises an exception if a directory does not exist
339+
# or if for any reason a directory cannot be removed.
302340
#
303341
def rmdir(list, parents: nil, noop: nil, verbose: nil)
304342
list = fu_list(list)

0 commit comments

Comments
 (0)