Class: Pathname

Inherits:
Object show all
Defined in:
lib/utilrb/pathname/find_matching_parent.rb

Instance Method Summary collapse

Instance Method Details

#find_matching_parent {|path| ... } ⇒ Pathname?

Returns the path object that is the first parent of self matching the given predicate

Yield Parameters:

  • path (Pathname)

    the path object that should be tested

Yield Returns:

  • (Boolean)

    true if this is the path you are looking for, and false otherwise

Returns:

  • (Pathname, nil)

    the matching path or nil if none could be found



10
11
12
13
14
15
16
17
18
19
# File 'lib/utilrb/pathname/find_matching_parent.rb', line 10

def find_matching_parent
    # Look for a bundle in the parents of Dir.pwd
    curdir = self
    while !curdir.root? && !yield(curdir)
        curdir = curdir.parent
    end
    if !curdir.root?
        curdir
    end
end