Class: Pathname

Inherits:
Object show all
Defined in:
lib/nano/pathname/ascend.rb,
lib/nano/pathname/descend.rb

Instance Method Summary collapse

Instance Method Details

#ascend(&block) ⇒ Object

Calls the block for every successive parent directory of the directory path until the root (absolute path) or . (relative path) is reached.



11
12
13
14
15
16
17
# File 'lib/nano/pathname/ascend.rb', line 11

def ascend(&block) # :yield:
  cur_dir = self
  until cur_dir.root? or cur_dir == Pathname.new(".")
    cur_dir = cur_dir.parent
    yield cur_dir
  end
end

#descendObject

Calls the block for every successive subdirectory of the directory path from the root (absolute path) unitl . (relative path) is reached.



11
12
13
14
15
16
# File 'lib/nano/pathname/descend.rb', line 11

def descend()
  @path.scan(%r{[^/]*/?})[0...-1].inject('') do |path, dir|
    yield Pathname.new(path << dir)
  path
  end
end