@@ -110,7 +110,11 @@ def self.private_module_function(name) #:nodoc:
110
110
end
111
111
112
112
#
113
- # Returns the name of the current directory.
113
+ # Returns a string containing the path to the current directory:
114
+ #
115
+ # FileUtils.pwd # => "/rdoc/fileutils"
116
+ #
117
+ # FileUtils.getwd is an alias for FileUtils.pwd.
114
118
#
115
119
def pwd
116
120
Dir . pwd
@@ -121,18 +125,36 @@ def pwd
121
125
module_function :getwd
122
126
123
127
#
124
- # Changes the current directory to the directory +dir+.
128
+ # With no block given,
129
+ # changes the current directory to the directory
130
+ # at the path given by +dir+; returns zero:
131
+ #
132
+ # FileUtils.pwd # => "/rdoc/fileutils"
133
+ # FileUtils.cd('..')
134
+ # FileUtils.pwd # => "/rdoc"
135
+ # FileUtils.cd('fileutils')
136
+ #
137
+ # With a block given, changes the current directory to the directory
138
+ # at the path given by +dir+, calls the block with argument +dir+,
139
+ # and restores the original current directory; returns the block's value:
125
140
#
126
- # If this method is called with block, resumes to the previous
127
- # working directory after the block execution has finished.
141
+ # FileUtils.pwd # => "/rdoc/fileutils"
142
+ # FileUtils.cd('..') { |arg| [arg, FileUtils.pwd] } # => ["..", "/rdoc"]
143
+ # FileUtils.pwd # => "/rdoc/fileutils"
128
144
#
129
- # FileUtils.cd('/') # change directory
145
+ # Keyword arguments:
130
146
#
131
- # FileUtils.cd('/', verbose: true) # change directory and report it
147
+ # - <tt> verbose: true</tt> - prints an equivalent command:
132
148
#
133
- # FileUtils.cd('/') do # change directory
134
- # # ... # do something
135
- # end # return to original directory
149
+ # FileUtils.cd('..')
150
+ # FileUtils.cd('fileutils')
151
+ #
152
+ # Output:
153
+ #
154
+ # cd ..
155
+ # cd fileutils
156
+ #
157
+ # FileUtils.chdir is an alias for FileUtils.cd.
136
158
#
137
159
def cd ( dir , verbose : nil , &block ) # :yield: dir
138
160
fu_output_message "cd #{ dir } " if verbose
@@ -146,11 +168,14 @@ def cd(dir, verbose: nil, &block) # :yield: dir
146
168
module_function :chdir
147
169
148
170
#
149
- # Returns true if +new+ is newer than all +old_list+.
150
- # Non-existent files are older than any file.
171
+ # Returns +true+ if the file at path +new+
172
+ # is newer than all the files at paths in array +old_list+.;
173
+ # +false+ otherwise:
174
+ #
175
+ # FileUtils.uptodate?('Rakefile', ['Gemfile', 'README.md']) # => true
176
+ # FileUtils.uptodate?('Gemfile', ['Rakefile', 'README.md']) # => false
151
177
#
152
- # FileUtils.uptodate?('hello.o', %w(hello.c hello.h)) or \
153
- # system 'make hello.o'
178
+ # A non-existent file is considered to be infinitely old.
154
179
#
155
180
def uptodate? ( new , old_list )
156
181
return false unless File . exist? ( new )
@@ -170,12 +195,32 @@ def remove_trailing_slash(dir) #:nodoc:
170
195
private_module_function :remove_trailing_slash
171
196
172
197
#
173
- # Creates one or more directories.
198
+ # Creates directories at the paths in the given +list+ (an array of strings);
199
+ # returns +list+.
200
+ #
201
+ # With no keyword arguments, creates a directory at each +path+ in +list+
202
+ # by calling: <tt>Dir.mkdir(path, mode)</tt>;
203
+ # see {Dir.mkdir}[https://docs.ruby-lang.org/en/master/Dir.html#method-c-mkdir]:
204
+ #
205
+ # FileUtils.mkdir(%w[tmp0 tmp1]) # => ["tmp0", "tmp1"]
206
+ #
207
+ # Keyword arguments:
208
+ #
209
+ # - <tt>mode: <i>integer</i></tt> - also calls <tt>File.chmod(mode, path)</tt>;
210
+ # see {File.chmod}[https://docs.ruby-lang.org/en/master/File.html#method-c-chmod].
211
+ # - <tt>noop: true</tt> - does not create directories.
212
+ # - <tt>verbose: true</tt> - prints an equivalent command:
213
+ #
214
+ # FileUtils.mkdir(%w[tmp0 tmp1], verbose: true)
215
+ # FileUtils.mkdir(%w[tmp2 tmp3], mode: 0700, verbose: true)
216
+ #
217
+ # Output:
218
+ #
219
+ # mkdir tmp0 tmp1
220
+ # mkdir -m 700 tmp2 tmp3
174
221
#
175
- # FileUtils.mkdir 'test'
176
- # FileUtils.mkdir %w(tmp data)
177
- # FileUtils.mkdir 'notexist', noop: true # Does not really create.
178
- # FileUtils.mkdir 'tmp', mode: 0700
222
+ # Raises an exception if any path in +list+ points to an existing
223
+ # file or directory, or if for any reason a directory cannot be created.
179
224
#
180
225
def mkdir ( list , mode : nil , noop : nil , verbose : nil )
181
226
list = fu_list ( list )
0 commit comments