Project

General

Profile

Actions

Feature #2149

closed

Pathname#include?

Added by erikh (Erik Hollensbe) about 15 years ago. Updated almost 7 years ago.

Status:
Feedback
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 #1

Updated by znz (Kazuhiro NISHIYAMA) over 14 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

=begin

=end

Actions #2

Updated by yhara (Yutaka HARA) about 12 years ago

  • Description updated (diff)
  • Target version changed from 2.0.0 to 2.6

Updated by mame (Yusuke Endoh) about 7 years ago

  • Status changed from Assigned to Feedback

I asked akr's opinion.

He looks neutral to this proposal, but we need to work out details. The current PoC implementation wrongly allows /foo/bar to match with /fo. Also, we need a better name than include?, which should be more suitable to the detailed spec of the method.

Actions #4

Updated by naruse (Yui NARUSE) almost 7 years ago

  • Target version deleted (2.6)
Actions #5

Updated by naruse (Yui NARUSE) almost 7 years ago

  • Description updated (diff)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0