End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
FileUtils.chdir
chdir(dir, verbose: nil)
lib/fileutils.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/fileutils.rb, line 242
def cd(dir, verbose: nil, &block) # :yield: dir
fu_output_message "cd #{dir}" if verbose
result = Dir.chdir(dir, &block)
fu_output_message 'cd -' if verbose and block
result
end
Alias of .cd
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:
Example
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:
Example
FileUtils.pwd # => "/rdoc/fileutils" FileUtils.cd('..') { |arg| [arg, FileUtils.pwd] } # => ["..", "/rdoc"] FileUtils.pwd # => "/rdoc/fileutils"
Keyword arguments:
-
verbose: true- prints an equivalent command:ExampleFileUtils.cd('..') FileUtils.cd('fileutils')
Output:
cd .. cd fileutils
FileUtils.chdir is an alias for FileUtils.cd.
Related: FileUtils.pwd.