class Pathname

Public Class Methods

/(path) click to toggle source

Active path separator.

p1 = Pathname.new('/')
p2 = p1 / 'usr' / 'share'   #=> Pathname:/usr/share
# File lib/more/facets/pathname.rb, line 41
def self./(path)
  new(path)
end
[](path) click to toggle source

Alternate to Pathname#new.

Pathname['/usr/share']
# File lib/more/facets/pathname.rb, line 32
def self.[](path)
  new(path)
end
home() click to toggle source

Home constant for building paths from root directory onward.

TODO: Pathname#home needs to be more robust.

# File lib/more/facets/pathname.rb, line 54
def self.home
  Pathname.new('~')
end
null() click to toggle source

Platform dependent null device.

# File lib/more/facets/pathname.rb, line 71
def self.null
  case RUBY_PLATFORM
  when %rmswin/
    'NUL'
  when %ramiga/
    'NIL:'
  when %ropenvms/
    'NL:'
  else
    '/dev/null'
  end
end
root() click to toggle source

Root constant for building paths from root directory onward.

# File lib/more/facets/pathname.rb, line 46
def self.root
  Pathname.new('/')
end
work() click to toggle source

Work constant for building paths from root directory onward.

# File lib/more/facets/pathname.rb, line 60
def self.work
  Pathname.new('.')
end

Public Instance Methods

empty?() click to toggle source
# File lib/more/facets/pathname.rb, line 155
def empty?
  Dir.glob(::File.join(self.to_s, '*')).empty?
end
glob(match, *opts) click to toggle source
# File lib/more/facets/pathname.rb, line 128
def glob(match, *opts)
  flags = 0
  opts.each do |opt|
    case opt when Symbol, String
      flags += ::File.const_get("FNM_#{opt}".upcase)
    else
      flags += opt
    end
  end
  Dir.glob(::File.join(self.to_s, match), flags).collect{ |m| self.class.new(m) }
end
glob_first(match, *opts) click to toggle source
# File lib/more/facets/pathname.rb, line 141
def glob_first(match, *opts)
  flags = 0
  opts.each do |opt|
    case opt when Symbol, String
      flags += ::File.const_get("FNM_#{opt}".upcase)
    else
      flags += opt
    end
  end
  file = ::Dir.glob(::File.join(self.to_s, match), flags).first
  file ? self.class.new(file) : nil
end
outofdate?(*sources) click to toggle source
# File lib/more/facets/pathname.rb, line 165
def outofdate?(*sources)
  ::FileUtils.outofdate?(to_s, sources.flatten)
end
rootname() click to toggle source
# File lib/more/facets/pathname.rb, line 85
def rootname
  self.class.new(File.rootname(to_s))
end
split_root() click to toggle source
# File lib/more/facets/pathname.rb, line 122
def split_root
  head, tail = *::File.split_root(to_s)
  [self.class.new(head), self.class.new(tail)]
end
uptodate?(*sources) click to toggle source
# File lib/more/facets/pathname.rb, line 160
def uptodate?(*sources)
  ::FileUtils.uptodate?(to_s, sources.flatten)
end