Feature #2149

Pathname#include?

Added by Erik Hollensbe over 4 years ago. Updated over 1 year ago.

[ruby-core:25811]
Status:Assigned
Priority:Normal
Assignee:Akira Tanaka
Category:lib
Target version:next minor

Description

=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?(otherpath)
case other
path
when String
otherpath = Pathname.new(otherpath)
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

History

#1 Updated by Kazuhiro NISHIYAMA about 4 years ago

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

=begin

=end

#2 Updated by Yutaka HARA over 1 year ago

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

Also available in: Atom PDF