From: Power One Date: 2009-03-09T02:10:12+09:00 Subject: Re: I code my first ruby script, and it got problem! Once again, thank so much Park! I wonder why do I have to use ensure to have the subsequent method del_dir to work? After seeing you used ensure, I read on the Internet, it says that ensure is helping to make sure the code block within ensure will always be executed. Though when I do Dir.chdir("#{@dirname}"), isn't this adequate? I saw that you have to use cwd = Dir.pwd, and then do Dir.chdir, and then do ensure again! Just out of curiosity as I really want to understand Ruby's process. Thank You so much, please help explain :). Heesob Park wrote: > 2009/3/8 Power One : >>>   if @dirname = gets >> gets.chomp did the job perfectly, but my very last code is like >>      puts "#{@dirname} is still here!" >>    end >>    end >> > The del_dir method has no problem. > > The problem is due to see_me method. > Modify see_me something like this will work. > > def see_me > if File.exist?("#{@dirname}") > cwd = Dir.pwd > begin > Dir.chdir("#{@dirname}") > puts Dir.pwd > ensure > Dir.chdir(cwd) > end > else > puts "This directory #{@dirname} is not exist!" > end > end > > > Regards, > > Park Heesob -- Posted via http://www.ruby-forum.com/.