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
Alternate to Pathname#new.
Pathname['/usr/share']
# File lib/more/facets/pathname.rb, line 32 def self.[](path) new(path) end
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
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 constant for building paths from root directory onward.
# File lib/more/facets/pathname.rb, line 46 def self.root Pathname.new('/') end
Work constant for building paths from root directory onward.
# File lib/more/facets/pathname.rb, line 60 def self.work Pathname.new('.') end
# File lib/more/facets/pathname.rb, line 155 def empty? Dir.glob(::File.join(self.to_s, '*')).empty? end
# 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
# 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
# File lib/more/facets/pathname.rb, line 165 def outofdate?(*sources) ::FileUtils.outofdate?(to_s, sources.flatten) end
# File lib/more/facets/pathname.rb, line 85 def rootname self.class.new(File.rootname(to_s)) end
# 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
# File lib/more/facets/pathname.rb, line 160 def uptodate?(*sources) ::FileUtils.uptodate?(to_s, sources.flatten) end