lib/pleasant_path/pathname.rb
def chdir
    if block_given?
      Dir.chdir(self) do |dir|
        yield dir.to_pathname
      end
    else
      Dir.chdir(self)
      self
    end
  end
# Changes the current working directory to the Pathname.  If no block
# is given, this method returns the Pathname.  Otherwise, the block is
# called with the Pathname, the original working directory is restored
# after the block exits, and this method returns the return value of
# the block.
#
# @see https://docs.ruby-lang.org/en/master/Dir.html#method-c-chdir Dir.chdir
#
# @example
#   FileUtils.mkdir("dir1")
#   FileUtils.mkdir("dir2")
#
#   Pathname.new("dir1").chdir  # == Pathname.new("dir1")
#   Pathname.pwd                # == Pathname.new("dir1")
#
#   Pathname.new("dir2").chdir{|path| "in #{path}" }  # == "in dir2"
#   Pathname.pwd                                      # == Pathname.new("dir1")
#
# @overload chdir()
#   @return [self]
#
# @overload chdir(&block)
#   @yieldparam working_dir [Pathname]
#   @yieldreturn [Object]
#   @return [Object]
#
# @raise [SystemCallError]
#   if the Pathname does not point to an existing directory
Changes the current working directory to the Pathname.  If no block
is given, this method returns the Pathname.  Otherwise, the block is
called with the Pathname, the original working directory is restored
after the block exits, and this method returns the return value of
the block.
Changes the current working directory to the Pathname . If no block is given this method returns the Pathname . Otherwise the block is called with the Pathname the original working directory is restored after the block exits and this method returns the return value of the block .
def chdir
    if block_given?
      Dir.chdir(self) do |dir|
        yield dir.to_pathname
      end
    else
      Dir.chdir(self)
      self
    end
  end
def chdir if block_given? Dir . chdir ( self ) do | dir | yield dir . to_pathname end else Dir . chdir ( self ) self end end
Changes the current working directory to the Pathname.
Changes the current working directory to the Pathname .
[SystemCallError] if the Pathname does not point to an existing directory
[ SystemCallError ] if the Pathname does not point to an existing directory
see
None
example
FileUtils.mkdir("dir1") FileUtils.mkdir("dir2") Pathname.new("dir1").chdir # == Pathname.new("dir1") Pathname.pwd # == Pathname.new("dir1") Pathname.new("dir2").chdir{|path| "in #{path}" } # == "in dir2" Pathname.pwd # == Pathname.new("dir1")
FileUtils . mkdir ( " dir1 " ) FileUtils . mkdir ( " dir2 " ) Pathname . new ( " dir1 " ) . chdir # == Pathname . new ( " dir1 " ) Pathname . pwd # == Pathname . new ( " dir1 " ) Pathname . new ( " dir2 " ) . chdir { |path| " in # { path } " } # == " in dir2 " Pathname . pwd # == Pathname . new ( " dir1 " )
overload
chdir() @return [self]
chdir () @return [ self ]
overload
chdir(█) @yieldparam working_dir [Pathname] @yieldreturn [Object] @return [Object]
chdir ( █ ) @yieldparam working_dir [ Pathname ] @yieldreturn [ Object ] @return [ Object ]