From: mame@... Date: 2017-10-22T00:47:28+00:00 Subject: [ruby-core:83483] [Ruby trunk Feature#2149][Feedback] Pathname#include? Issue #2149 has been updated by mame (Yusuke Endoh). 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. ---------------------------------------- Feature #2149: Pathname#include? https://bugs.ruby-lang.org/issues/2149#change-67490 * Author: erikh (Erik Hollensbe) * Status: Feedback * Priority: Normal * Assignee: akr (Akira Tanaka) * Target version: next minor ---------------------------------------- =begin 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
 
=end -- https://bugs.ruby-lang.org/ Unsubscribe: