Change the current directory without side effects in Ruby

Updated . Posted . Visible to the public.

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
Henning Koch
Last edit
Keywords
pwd, working, ruby
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2010-12-01 09:33)