Methods
/
[]
empty?
glob
glob_first
home
null
root
rootname
split_root
work
Public Class methods
Active path separator.
p1 = Pathname.new('/') p2 = p1 / 'usr' / 'share' #=> Pathname:/usr/share
[ + ]
# File lib/lore/facets/pathname.rb, line 41 def self./(path) new(path) end
Alternate to Pathname#new.
Pathname['/usr/share']
[ + ]
# File lib/lore/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/lore/facets/pathname.rb, line 54 def self.home Pathname.new('~') end
Platform dependent null device.
[ + ]
# File lib/lore/facets/pathname.rb, line 71 def self.null case RUBY_PLATFORM when /mswin/i 'NUL' when /amiga/i 'NIL:' when /openvms/i 'NL:' else '/dev/null' end end
Root constant for building paths from root directory onward.
[ + ]
# File lib/lore/facets/pathname.rb, line 46 def self.root Pathname.new('/') end
Work constant for building paths from root directory onward.
[ + ]
# File lib/lore/facets/pathname.rb, line 60 def self.work Pathname.new('.') end
Public Instance methods
[ + ]
# File lib/lore/facets/pathname.rb, line 155 def empty? Dir.glob(::File.join(self.to_s, '*')).empty? end
[ + ]
# File lib/lore/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/lore/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/lore/facets/pathname.rb, line 85 def rootname self.class.new(File.rootname(to_s)) end
[ + ]
# File lib/lore/facets/pathname.rb, line 122 def split_root head, tail = *::File.split_root(to_s) [self.class.new(head), self.class.new(tail)] end