Skip to content

Commit ab9f1a6

Browse files
andrykonchineregon
authored andcommitted
[GR-19220] Convert string arg to Pathname in relative_path_from
PullRequest: truffleruby/3830
2 parents 404a086 + 7b4fd94 commit ab9f1a6

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Compatibility:
1616
* Fix `Array#[]` with `ArithmeticSequence` argument when step is negative (#3039, @itarato).
1717
* Fix `Range#size` and return `nil` for beginningless Range when end isn't Numeric (#3039, @rwstauner).
1818
* Alias `String#-@` to `String#dedup` (#3039, @itarato).
19+
* Fix `Pathname#relative_path_from` to convert string arguments to Pathname objects (@rwstauner).
1920

2021
Performance:
2122

lib/truffle/pathname.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ def each_child(with_directory = true, &b)
763763
# This method has existed since 1.8.1.
764764
#
765765
def relative_path_from(base_directory)
766+
base_directory = Pathname.new(base_directory) unless Primitive.is_a?(base_directory, Pathname)
766767
dest_directory = self.cleanpath.to_s
767768
base_directory = base_directory.cleanpath.to_s
768769
dest_prefix = dest_directory

spec/ruby/library/pathname/relative_path_from_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ def relative_path_str(dest, base)
4848
relative_path_str('..', '..').should == '.'
4949
relative_path_str('..', '.').should == '..'
5050
end
51+
52+
it 'converts string argument to Pathname' do
53+
Pathname.new('/usr/bin/ls').relative_path_from('/usr').to_s.should == 'bin/ls'
54+
end
5155
end

0 commit comments

Comments
 (0)