11class Pathname
22
3- # Glob pathnames.
3+ # Extends Ruby's built-in Pathname#glob to accept symbol-based
4+ # flags in addition to the standard File::FNM_* constants.
5+ #
6+ # Pathname.new('/tmp').glob('*', :dotmatch)
7+ #
8+ # Supported symbols: :noescape, :pathname, :dotmatch, :casefold
9+ #
10+ alias_method :_glob_original , :glob
11+ private :_glob_original
12+
413 def glob ( match , *opts )
5- flags = glob_flags ( opts )
6- Dir . glob ( ::File . join ( self . to_s , match ) , flags ) . collect { |m | self . class . new ( m ) }
14+ if opts . any? { |o | o . is_a? ( Symbol ) || o . is_a? ( String ) }
15+ flags = glob_flags ( opts )
16+ Dir . glob ( ::File . join ( self . to_s , match ) , flags ) . map { |m | self . class . new ( m ) }
17+ else
18+ _glob_original ( match , *opts )
19+ end
720 end
821
922 # Return the first glob match.
1023 #
11- # DEPRECATE: While slightly faster then glob().first, not really worth it
12- # unless this can be rewritten to shortcut on first match (using fnmatch?).
13- # In wich case, is there a better name for this method?
1424 def glob_first ( match , *opts )
1525 flags = glob_flags ( opts )
1626 file = ::Dir . glob ( ::File . join ( self . to_s , match ) , flags ) . first
@@ -28,15 +38,12 @@ def glob_relative(match, *opts)
2838 # Does a directory contain a matching entry?
2939 # Or if the pathname is a file, same as #fnmatch.
3040 #
31- # TODO: Move to own file? Better name?
32- #
3341 # Returns [Pathname]
34-
35- def include? ( pattern , *opts )
42+ def include? ( pattern , *opts )
3643 if directory?
37- glob_first ( pattern , *opts )
44+ glob_first ( pattern , *opts )
3845 else
39- fnmatch ( pattern , *opts )
46+ fnmatch ( pattern , *opts )
4047 end
4148 end
4249
0 commit comments