diff options
| author | schneems <richard.schneeman+foo@gmail.com> | 2020-10-26 13:46:40 -0500 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-10-04 12:21:27 +0900 |
| commit | 3c54b8e9205fa8debe09447138fd08aeaa59e69c (patch) | |
| tree | e2ad48df56f57cf3651ca2a44759b7da796a3281 /ext | |
| parent | 08346e7267b4f17ae207d67543d5f78c2541dc86 (diff) | |
Allow method chaining with Pathname#mkpath
Currently in my code when I want to create a pathname object and create a path at the same time I must use tap
```
path = Pathname.new("/tmp/new").tap(&:mkpath)
```
I think it would be cleaner to be able to chain on the results of these methods instead:
```
path = Pathname.new("/tmp/new").mkpath
```
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3705
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/pathname/lib/pathname.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 52e1d5cfbb..2deda00ff2 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -588,7 +588,7 @@ class Pathname # * FileUtils * def mkpath(mode: nil) require 'fileutils' FileUtils.mkpath(@path, mode: mode) - nil + self end # Recursively deletes a directory, including all directories beneath it. @@ -599,7 +599,7 @@ class Pathname # * FileUtils * # File::Path provides "mkpath" and "rmtree". require 'fileutils' FileUtils.rm_rf(@path, noop: noop, verbose: verbose, secure: secure) - nil + self end end @@ -619,4 +619,3 @@ class Pathname # * tmpdir * end end end - |
