Issue #10011 has been updated by Leif Eriksen.


ok so I have 2 possible fixes, one of which I've implemented

The unimplemented fix is maybe a new  method along the lines of to_s, but for paths, called to_pathname. Then we could reopen String and define
clas String
  def to_pathname
    Pathname.new self
  end
end

And so forth for any classes where converting to a pathname makes some semantic sense.

Then in relative_path_from can just do

base_directory.to_pathname.cleanpath.to_s at line 493, as in the above description.

But I can see that might be harder to get through than the actual, fairly naive fix I've done, which is to just convert base_directory to a Pathname if required,as per 
[[https://github.com/leriksen/ruby/commit/0ab29978bb83e485784fa426340ce91df30d2d13
]]

The test code seems to imply this is probably quite acceptable.

If the commit is preferred, I'll do a pull request tomorrow unless there are issues expressed here.

Or if the :to_pathname option is preferred, I implement that instead.


----------------------------------------
Bug #10011: Passing a string to Pathname#relative_path_from results in NoMethodError
https://bugs.ruby-lang.org/issues/10011#change-47676

* Author: Jack Nagel
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* ruby -v: ruby 2.2.0dev (2014-07-05 trunk 46706) [x86_64-darwin13]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
When a string is passed to Pathname#relative_path_from, a NoMethodError is raised.

```
irb(main):001:0> require "pathname"
=> true
irb(main):002:0> Pathname.new("/usr/bin/cc").relative_path_from Pathname.new("/usr/bin")
=> #<Pathname:cc>
irb(main):003:0> Pathname.new("/usr/bin/cc").relative_path_from("/usr/bin")
NoMethodError: undefined method `cleanpath' for "/usr/bin":String
	from /Users/jacknagel/.rubies/ruby-2.2.0/lib/ruby/2.2.0/pathname.rb:493:in `relative_path_from'
	from (irb):3
	from /Users/jacknagel/.rubies/ruby-2.2.0/bin/irb:11:in `<main>'
```

I think either converting the argument to a Pathname or raising TypeError would be acceptable here.



-- 
https://bugs.ruby-lang.org/