| 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
41: def self./(path)
42: new(path)
43: end
Alternate to Pathname#new.
Pathname['/usr/share']
# File lib/more/facets/pathname.rb, line 32
32: def self.[](path)
33: new(path)
34: 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
54: def self.home
55: Pathname.new('~')
56: end
# File lib/more/facets/pathname.rb, line 155
155: def empty?
156: Dir.glob(::File.join(self.to_s, '*')).empty?
157: end
# File lib/more/facets/pathname.rb, line 128
128: def glob(match, *opts)
129: flags = 0
130: opts.each do |opt|
131: case opt when Symbol, String
132: flags += File.const_get("FNM_#{opt}".upcase)
133: else
134: flags += opt
135: end
136: end
137: Dir.glob(::File.join(self.to_s, match), flags).collect{ |m| self.class.new(m) }
138: end
# File lib/more/facets/pathname.rb, line 141
141: def glob_first(match, *opts)
142: flags = 0
143: opts.each do |opt|
144: case opt when Symbol, String
145: flags += ::File.const_get("FNM_#{opt}".upcase)
146: else
147: flags += opt
148: end
149: end
150: file = ::Dir.glob(::File.join(self.to_s, match), flags).first
151: file ? self.class.new(file) : nil
152: end
# File lib/more/facets/pathname.rb, line 85
85: def rootname
86: self.class.new(File.rootname(to_s))
87: end