APIdock / Ruby
/
method

pushdir

ruby latest stable - Class: Shell
pushdir(path = nil, verbose = @verbose)
public

Pushes the current directory to the directory stack, changing the current directory to path.

If path is omitted, it exchanges its current directory and the top of its directory stack.

If a block is given, it restores the current directory when the block ends.

# File lib/shell.rb, line 296
 def pushdir(path = nil, verbose = @verbose)
 check_point
 if iterator?
 notify("pushdir(with block) #{path}") if verbose
 pushdir(path, nil)
 begin
 yield
 ensure
 popdir
 end
 elsif path
 notify("pushdir #{path}") if verbose
 @dir_stack.push @cwd
 chdir(path, nil)
 notify "dir stack: [#{@dir_stack.join ', '}]"
 self
 else
 notify("pushdir") if verbose
 if pop = @dir_stack.pop
 @dir_stack.push @cwd
 chdir pop
 notify "dir stack: [#{@dir_stack.join ', '}]"
 self
 else
 Shell.Fail DirStackEmpty
 end
 end
 Void.new(self)
 end

AltStyle によって変換されたページ (->オリジナル) /