diff --git a/lib/pathname_builtin.rb b/lib/pathname_builtin.rb index 3d78619..d9c5d5b 100644 --- a/lib/pathname_builtin.rb +++ b/lib/pathname_builtin.rb @@ -195,14 +195,12 @@ class Pathname # :stopdoc: - SAME_PATHS = if File::FNM_SYSCASE.nonzero? + if File::FNM_SYSCASE.nonzero? # Avoid #zero? here because #casecmp can return nil. - proc {|a, b| a.casecmp(b) == 0} + private def same_paths?(a, b) a.casecmp(b) == 0 end else - proc {|a, b| a == b} + private def same_paths?(a, b) a == b end end - SAME_PATHS.freeze - private_constant :SAME_PATHS attr_reader :path protected :path @@ -836,12 +834,12 @@ def relative_path_from(base_directory) base_prefix, basename = r base_names.unshift basename if basename != '.' end - unless SAME_PATHS[dest_prefix, base_prefix] + unless same_paths?(dest_prefix, base_prefix) raise ArgumentError, "different prefix: #{dest_prefix.inspect} and #{base_directory.inspect}" end while !dest_names.empty? && !base_names.empty? && - SAME_PATHS[dest_names.first, base_names.first] + same_paths?(dest_names.first, base_names.first) dest_names.shift base_names.shift end diff --git a/test/pathname/test_ractor.rb b/test/pathname/test_ractor.rb index f06b750..737e4a4 100644 --- a/test/pathname/test_ractor.rb +++ b/test/pathname/test_ractor.rb @@ -20,6 +20,11 @@ class Ractor x.join(Pathname("b"), Pathname("c")) end assert_equal(Pathname("a/b/c"), r.value) + + r = Ractor.new Pathname("a") do |a| + Pathname("b").relative_path_from(a) + end + assert_equal(Pathname("../b"), r.value) end; end end