Project

General

Profile

Actions

Feature #2149

open

Pathname#include?

Added by erikh (Erik Hollensbe) over 11 years ago. Updated over 3 years ago.

Status:
Feedback
Priority:
Normal
Target version:
-
[ruby-core:25811]

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.

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
Actions

Also available in: Atom PDF