
Issue #20056 has been updated by jeremyevans0 (Jeremy Evans). zverok (Victor Shepelev) wrote:
1. There is no block form for `Dir#chdir`, unlike `Dir.chdir` (the form that will return to the previous directory when the block is finished)
`Dir#chdir` implicitly calls `Dir.chdir` or `Dir.fchdir` with the passed block, so the block form does work, but it apparently is not documented: ```ruby p Dir.pwd # => '/home/jeremy' Dir.new('..').chdir{p Dir.pwd} # => '/home' p Dir.pwd # => '/home/jeremy' ```
2. `Dir.chdir` returns `0`, while `Dir#chdir` returns `nil` (both seem to be not representing any particular internal value, just a hardcoded return value).
Return value being `nil` is expected. I assume the only reason `Dir.chdir` returns `0` is backwards compatibility, as I highly doubt we would use `0` as the return value for success for new methods. ---------------------------------------- Misc #20056: Dir#chdir inconsistency with Dir.chdir https://bugs.ruby-lang.org/issues/20056#change-105617 * Author: zverok (Victor Shepelev) * Status: Open * Priority: Normal * Assignee: jeremyevans0 (Jeremy Evans) ---------------------------------------- I am not sure it is important; I just wanted to understand if this is intentional or accidental. 1. There is no block form for `Dir#chdir`, unlike `Dir.chdir` (the form that will return to the previous directory when the block is finished) 2. `Dir.chdir` returns `0`, while `Dir#chdir` returns `nil` (both seem to be not representing any particular internal value, just a hardcoded return value). -- https://bugs.ruby-lang.org/