Change the current directory without side effects in Ruby
To temporarily change the current working directory in Ruby, call Dir.chdir
with a block. The previous working directory will be restored when the block ends:
Dir.chdir('/usr/local') do
# do stuff in /usr/local
end