Class | Pathname |
In: |
lib/more/facets/pathname.rb
|
Parent: | Object |
+ | -> | / |
Try to get this into standard Pathname class. |
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
# 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