Method: FileUtils.chdir
- Defined in:
- lib/fileutils.rb
.chdir ⇒ Object
Changes the working directory to the given dir, which should be interpretable as a path:
With no block given, changes the current directory to the directory at dir; returns zero:
FileUtils.pwd # => "/rdoc/fileutils"
FileUtils.cd('..')
FileUtils.pwd # => "/rdoc"
FileUtils.cd('fileutils')
With a block given, changes the current directory to the directory at dir, calls the block with argument dir, and restores the original current directory; returns the block’s value:
FileUtils.pwd # => "/rdoc/fileutils"
FileUtils.cd('..') { |arg| [arg, FileUtils.pwd] } # => ["..", "/rdoc"]
FileUtils.pwd # => "/rdoc/fileutils"
Keyword arguments:
-
verbose: true- prints an equivalent command:FileUtils.cd('..') FileUtils.cd('fileutils')Output:
cd .. cd fileutils
Related: FileUtils.pwd.
247 248 249 250 251 252 |
# File 'lib/fileutils.rb', line 247 def cd(dir, verbose: nil, &block) # :yield: dir "cd #{dir}" if verbose result = Dir.chdir(dir, &block) 'cd -' if verbose and block result end |