Feature #2149

Pathname#include?

Added by erikh (Erik Hollensbe) over 2 years ago. Updated about 1 year ago.

[ruby-core:25811]
Status:Assigned Start date:09/28/2009
Priority:Normal Due date:
Assignee:akr (Akira Tanaka) % Done:

0%

Category:lib
Target version:2.0.0

Description

pre-cleaning the paths of both side of this call and seeing if the RHS exists in the LHS would be a very useful feature for Pathname users; especially those who are trying to evaluate whether or not a path (after cleanup) is a child of another.

I wrote up a basic implementation, and would be happy to bulletproof it (it doesn't handle relative paths right now, for instance) and write a more formal patch if this is an acceptable addition.

<pre>
class Pathname
    def include?(other_path)
        case other_path
        when String
           other_path = Pathname.new(other_path) 
        when Pathname
        else
            raise "#{other_path.inspect}: Not a Pathname"
        end

        !!(self.cleanpath.to_s.index(other_path.cleanpath.to_s, 0) == 0)
    end
end
</pre>

History

Updated by znz (Kazuhiro NISHIYAMA) about 2 years ago

  • Category set to lib
  • Status changed from Open to Assigned
  • Assignee set to akr (Akira Tanaka)
  • Target version set to 2.0.0

Also available in: Atom PDF