Class Pathname
In: lib/more/facets/pathname.rb
Parent: Object

Methods

/   []   empty?   glob   glob_first   glob_relative   home   include?   null   outofdate?   root   rootname   split_root   uptodate?   visit   work  

External Aliases

to_s -> to_str
  Alias to_s to to_str when to_str is not defined.
+ -> /
  Try to get this into standard Pathname class.

Public Class methods

Start a path. Another alias for new.

  Pathname / 'usr'

Alternate to Pathname#new.

  Pathname['/usr/share']

Home constant for building paths from root directory onward.

TODO: Pathname#home needs to be more robust.

Platform dependent null device.

CREDIT Daniel Burger

Root constant for building paths from root directory onward.

Work constant for building paths from root directory onward.

Public Instance methods

Glob pathnames.

Return the first glob match.

DEPRECATE: While slightly faster then glob().first, not really worth it unless this can be rewritten to shortcut on first match (using fnmatch?). In wich case, is there a better name for this method?

Return globbed matches with pathnames relative to the current pathname.

Does a directory contain a matching entry? Or if the pathname is a file, same as fnmatch.

Recursively visit a directory located by its path, yielding each resource as its full matching pathname object. If called on a file, yield the file.

Example use case:

  # Locate any file but *.haml within app/**/*
  Pathname.new("app").visit do |f|
    next unless f.to_s =~ /\.haml$/
    f
  end

TODO: Use map instead of each ?

CREDIT: Jean-Denis Vauguet

[Validate]