mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
Support passing a #to_str object to Pathname.new for compatibility
* See https://github.com/ruby/pathname/pull/57#issuecomment-3485646510
This commit is contained in:
1 parent
f8e9bccd03
commit
f8d1291162
2 files changed
+6
-1
No files matched your search
+2
-1
@@ -217,7 +217,8 @@ class Pathname
|
||||
def initialize(path)
|
||||
unless String === path
|
||||
path = path.to_path if path.respond_to? :to_path
|
||||
raise TypeError unless String === path
|
||||
path = path.to_str if path.respond_to? :to_str
|
||||
raise TypeError, "Pathname.new requires a String, #to_path or #to_str" unless String === path
|
||||
end
|
||||
|
||||
if path.include?("\0")
|
||||
|
||||
@@ -484,6 +484,10 @@ class TestPathname < Test::Unit::TestCase
|
||||
assert_equal('a', p1.to_s)
|
||||
p2 = Pathname.new(p1)
|
||||
assert_equal(p1, p2)
|
||||
|
||||
obj = Object.new
|
||||
def obj.to_str; "a/b"; end
|
||||
assert_equal("a/b", Pathname.new(obj).to_s)
|
||||
end
|
||||
|
||||
def test_initialize_nul
|
||||
|
||||
Reference in new issue
Block a user