require 'pathname' class Pathname # Already included in 1.8.4+ version of Ruby if not instance_methods.include?(:ascend) # Calls the _block_ for every successive parent directory of the # directory path until the root (absolute path) or +.+ (relative path) # is reached. def ascend(inclusive=false,&block) # :yield: cur_dir = self yield( cur_dir.cleanpath ) if inclusive until cur_dir.root? or cur_dir == Pathname.new(".") cur_dir = cur_dir.parent yield cur_dir end end end end