Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Exercise3. Make use of the class Dir for the following -
#
# Display your current working directory.
# Create a new directory tmp under your working directory.
# Change your working directory to tmp
# Display your current working directory.
# Go back to your original directory.
# Delete the tmp directory.
puts "1. #{ENV['PWD']}"
Dir.mkdir('tmp') unless Dir.exists?('tmp')
Dir.chdir("/tmp")
puts "2. #{ENV['PWD']}" # => not in tmp
Dir.chdir('..')
puts "3. #{ENV['PWD']}"
Dir.delete('tmp') # => Errno::EACCES: Permission denied - tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.