Chdir Method with Block

Posted by root Fri, 22 Aug 2008 15:13:00 GMT

# temporary changes the cwd to '/tmp',
# adds content to a file and finally restores cwd

p Dir.getwd

Dir.chdir("/tmp") do
  p Dir.getwd
  File.open("test.txt", "a") do |f|
    f << Time.now << "\n"
  end
end

p Dir.getwd

Posted in  | Tags  | no comments | no trackbacks

Comments

Trackbacks

Use the following link to trackback from your own site:
http://www.vidul.com/articles/trackback/81

Comments are disabled