From: Mark Wilson Date: 2003-02-08T06:32:41+09:00 Subject: Re: Dir.pushdir and Dir.popdir On Friday, February 7, 2003, at 04:10 PM, Wesley J Landaker wrote: > [snip] > I don't know if this functionality is included somewhere else and I > just > missed it, but it sure is handy to have Dir be able to push and pop > directories as well as just chdir. I often use something like this: > > [snip] The standard library includes this functionality in shell.rb. pushdir(path = nil) {|| ...} # File lib/shell.rb, line 163 def pushdir(path = nil) if iterator? pushdir(path) begin yield ensure popdir end elsif path @dir_stack.push @cwd chdir path notify "dir stack: [#{@dir_stack.join ', '}]" self else if pop = @dir_stack.pop @dir_stack.push @cwd chdir pop notify "dir stack: [#{@dir_stack.join ', '}]" self else Shell.Fail DirStackEmpty end end end popdir() # File lib/shell.rb, line 189 def popdir if pop = @dir_stack.pop chdir pop notify "dir stack: [#{@dir_stack.join ', '}]" self else Shell.Fail DirStackEmpty end end