summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2026-05-03 21:01:43 +0900
committerNobuyoshi Nakada <nobu.nakada@gmail.com>2026-05-13 17:37:48 +0900
commit41542767d2aae4a5ab5962a021eaa2619becb0ea (patch)
tree5591ba1991dff3573f27a76b7b34e631f1d1dd35
parentde8d33295d07c61783f5a68e435bc749faa87b25 (diff)
pathname: Reuse dirname results
-rw-r--r--pathname_builtin.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/pathname_builtin.rb b/pathname_builtin.rb
index 4bd8b002f3..84b2bf2848 100644
--- a/pathname_builtin.rb
+++ b/pathname_builtin.rb
@@ -299,9 +299,9 @@ class Pathname
path = @path == '/' ? @path : @path.chomp('/')
stack = []
- until File.directory?(path) || File.dirname(path) == path
+ until File.directory?(path) || (parent = File.dirname(path)) == path
stack.push path
- path = File.dirname(path)
+ path = parent
end
stack.reverse_each do |dir|