summaryrefslogtreecommitdiff
path: root/dir.rb
diff options
context:
space:
mode:
Diffstat (limited to 'dir.rb')
-rw-r--r--dir.rb132
1 files changed, 28 insertions, 104 deletions
diff --git a/dir.rb b/dir.rb
index 7de62da921..9436b48f47 100644
--- a/dir.rb
+++ b/dir.rb
@@ -31,7 +31,7 @@
# A \Dir object is in some ways array-like:
#
# - It has instance methods #children, #each, and #each_child.
-# - It includes {module Enumerable}[rdoc-ref:Enumerable@What-27s+Here].
+# - It includes {module Enumerable}[rdoc-ref:Enumerable@Whats+Here].
#
# == \Dir As Stream-Like
#
@@ -46,14 +46,14 @@
# The stream has a _position_, which is the index of an entry in the directory:
#
# - The initial position is zero (before the first entry).
-# - \Method #tell (aliased as #pos) returns the position.
-# - \Method #pos= sets the position (but ignores a value outside the stream),
+# - Method #tell (aliased as #pos) returns the position.
+# - Method #pos= sets the position (but ignores a value outside the stream),
# and returns the position.
-# - \Method #seek is like #pos=, but returns +self+ (convenient for chaining).
-# - \Method #read, if not at end-of-stream, reads the next entry and increments
+# - Method #seek is like #pos=, but returns +self+ (convenient for chaining).
+# - Method #read, if not at end-of-stream, reads the next entry and increments
# the position;
# if at end-of-stream, does not increment the position.
-# - \Method #rewind sets the position to zero.
+# - Method #rewind sets the position to zero.
#
# Examples (using the {simple file tree}[rdoc-ref:Dir@About+the+Examples]):
#
@@ -83,10 +83,10 @@
#
# == What's Here
#
-# First, what's elsewhere. \Class \Dir:
+# First, what's elsewhere. Class \Dir:
#
-# - Inherits from {class Object}[rdoc-ref:Object@What-27s+Here].
-# - Includes {module Enumerable}[rdoc-ref:Enumerable@What-27s+Here],
+# - Inherits from {class Object}[rdoc-ref:Object@Whats+Here].
+# - Includes {module Enumerable}[rdoc-ref:Enumerable@Whats+Here],
# which provides dozens of additional methods.
#
# Here, class \Dir provides methods that are useful for:
@@ -178,7 +178,7 @@ class Dir
# if +nil+ (the default), the file system's encoding is used:
#
# Dir.open('.').read.encoding # => #<Encoding:UTF-8>
- # Dir.open('.', encoding: 'US-ASCII').read.encoding # => #<Encoding:US-ASCII>
+ # Dir.open('.', encoding: Encoding::US_ASCII).read.encoding # => #<Encoding:US-ASCII>
#
def self.open(name, encoding: nil, &block)
dir = Primitive.dir_s_open(name, encoding)
@@ -206,7 +206,7 @@ class Dir
# if +nil+ (the default), the file system's encoding is used:
#
# Dir.new('.').read.encoding # => #<Encoding:UTF-8>
- # Dir.new('.', encoding: 'US-ASCII').read.encoding # => #<Encoding:US-ASCII>
+ # Dir.new('.', encoding: Encoding::US_ASCI).read.encoding # => #<Encoding:US-ASCII>
#
def initialize(name, encoding: nil)
Primitive.dir_initialize(name, encoding)
@@ -224,8 +224,8 @@ class Dir
end
# call-seq:
- # Dir.glob(*patterns, flags: 0, base: nil, sort: true) -> array
- # Dir.glob(*patterns, flags: 0, base: nil, sort: true) {|entry_name| ... } -> nil
+ # Dir.glob(patterns, flags: 0, base: nil, sort: true) -> array
+ # Dir.glob(patterns, flags: 0, base: nil, sort: true) {|entry_name| ... } -> nil
#
# Forms an array _entry_names_ of the entry names selected by the arguments.
#
@@ -319,16 +319,16 @@ class Dir
#
# Dir.glob('io.?') # => ["io.c"]
#
- # - <tt>'[_set_]'</tt>: Matches any one character in the string _set_;
- # behaves like a {Regexp character class}[rdoc-ref:regexp.rdoc@Character+Classes],
+ # - <tt>'[set]'</tt>: Matches any one character in the string _set_;
+ # behaves like a {Regexp character class}[rdoc-ref:Regexp@Character+Classes],
# including set negation (<tt>'[^a-z]'</tt>):
#
# Dir.glob('*.[a-z][a-z]').take(3)
# # => ["CONTRIBUTING.md", "COPYING.ja", "KNOWNBUGS.rb"]
#
- # - <tt>'{_abc_,_xyz_}'</tt>:
+ # - <tt>'{abc,xyz}'</tt>:
# Matches either string _abc_ or string _xyz_;
- # behaves like {Regexp alternation}[rdoc-ref:regexp.rdoc@Alternation]:
+ # behaves like {Regexp alternation}[rdoc-ref:Regexp@Alternation]:
#
# Dir.glob('{LEGAL,BSDL}') # => ["LEGAL", "BSDL"]
#
@@ -388,10 +388,10 @@ class Dir
#
# - File::FNM_EXTGLOB:
# enables the pattern extension
- # <tt>'{_a_,_b_}'</tt>, which matches pattern _a_ and pattern _b_;
+ # <tt>'{a,b}'</tt>, which matches pattern _a_ and pattern _b_;
# behaves like a
# {regexp union}[rdoc-ref:Regexp.union]
- # (e.g., <tt>'(?:_a_|_b_)'</tt>):
+ # (e.g., <tt>'(?:a|b)'</tt>):
#
# pattern = '{LEGAL,BSDL}'
# Dir.glob(pattern) # => ["LEGAL", "BSDL"]
@@ -408,97 +408,21 @@ class Dir
# specifies that patterns may match short names if they exist; Windows only.
#
def self.glob(pattern, _flags = 0, flags: _flags, base: nil, sort: true)
+ Primitive.attr! :use_block
Primitive.dir_s_glob(pattern, flags, base, sort)
end
end
class << File
+
+ # :markup: markdown
+ #
# call-seq:
- # File.fnmatch( pattern, path, [flags] ) -> (true or false)
- # File.fnmatch?( pattern, path, [flags] ) -> (true or false)
- #
- # Returns true if +path+ matches against +pattern+. The pattern is not a
- # regular expression; instead it follows rules similar to shell filename
- # globbing. It may contain the following metacharacters:
- #
- # <code>*</code>::
- # Matches any file. Can be restricted by other values in the glob.
- # Equivalent to <code>/.*/x</code> in regexp.
- #
- # <code>*</code>:: Matches all regular files
- # <code>c*</code>:: Matches all files beginning with <code>c</code>
- # <code>*c</code>:: Matches all files ending with <code>c</code>
- # <code>\*c*</code>:: Matches all files that have <code>c</code> in them
- # (including at the beginning or end).
- #
- # To match hidden files (that start with a <code>.</code>) set the
- # File::FNM_DOTMATCH flag.
- #
- # <code>**</code>::
- # Matches directories recursively or files expansively.
- #
- # <code>?</code>::
- # Matches any one character. Equivalent to <code>/.{1}/</code> in regexp.
- #
- # <code>[set]</code>::
- # Matches any one character in +set+. Behaves exactly like character sets
- # in Regexp, including set negation (<code>[^a-z]</code>).
- #
- # <code>\\</code>::
- # Escapes the next metacharacter.
- #
- # <code>{a,b}</code>::
- # Matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled.
- # Behaves like a Regexp union (<code>(?:a|b)</code>).
- #
- # +flags+ is a bitwise OR of the <code>FNM_XXX</code> constants. The same
- # glob pattern and flags are used by Dir::glob.
- #
- # Examples:
- #
- # File.fnmatch('cat', 'cat') #=> true # match entire string
- # File.fnmatch('cat', 'category') #=> false # only match partial string
- #
- # File.fnmatch('c{at,ub}s', 'cats') #=> false # { } isn't supported by default
- # File.fnmatch('c{at,ub}s', 'cats', File::FNM_EXTGLOB) #=> true # { } is supported on FNM_EXTGLOB
- #
- # File.fnmatch('c?t', 'cat') #=> true # '?' match only 1 character
- # File.fnmatch('c??t', 'cat') #=> false # ditto
- # File.fnmatch('c*', 'cats') #=> true # '*' match 0 or more characters
- # File.fnmatch('c*t', 'c/a/b/t') #=> true # ditto
- # File.fnmatch('ca[a-z]', 'cat') #=> true # inclusive bracket expression
- # File.fnmatch('ca[^t]', 'cat') #=> false # exclusive bracket expression ('^' or '!')
- #
- # File.fnmatch('cat', 'CAT') #=> false # case sensitive
- # File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD) #=> true # case insensitive
- # File.fnmatch('cat', 'CAT', File::FNM_SYSCASE) #=> true or false # depends on the system default
- #
- # File.fnmatch('?', '/', File::FNM_PATHNAME) #=> false # wildcard doesn't match '/' on FNM_PATHNAME
- # File.fnmatch('*', '/', File::FNM_PATHNAME) #=> false # ditto
- # File.fnmatch('[/]', '/', File::FNM_PATHNAME) #=> false # ditto
- #
- # File.fnmatch('\?', '?') #=> true # escaped wildcard becomes ordinary
- # File.fnmatch('\a', 'a') #=> true # escaped ordinary remains ordinary
- # File.fnmatch('\a', '\a', File::FNM_NOESCAPE) #=> true # FNM_NOESCAPE makes '\' ordinary
- # File.fnmatch('[\?]', '?') #=> true # can escape inside bracket expression
- #
- # File.fnmatch('*', '.profile') #=> false # wildcard doesn't match leading
- # File.fnmatch('*', '.profile', File::FNM_DOTMATCH) #=> true # period by default.
- # File.fnmatch('.*', '.profile') #=> true
- #
- # File.fnmatch('**/*.rb', 'main.rb') #=> false
- # File.fnmatch('**/*.rb', './main.rb') #=> false
- # File.fnmatch('**/*.rb', 'lib/song.rb') #=> true
- # File.fnmatch('**.rb', 'main.rb') #=> true
- # File.fnmatch('**.rb', './main.rb') #=> false
- # File.fnmatch('**.rb', 'lib/song.rb') #=> true
- # File.fnmatch('*', 'dave/.profile') #=> true
- #
- # File.fnmatch('**/foo', 'a/b/c/foo', File::FNM_PATHNAME) #=> true
- # File.fnmatch('**/foo', '/a/b/c/foo', File::FNM_PATHNAME) #=> true
- # File.fnmatch('**/foo', 'c:/a/b/c/foo', File::FNM_PATHNAME) #=> true
- # File.fnmatch('**/foo', 'a/.b/c/foo', File::FNM_PATHNAME) #=> false
- # File.fnmatch('**/foo', 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
+ # File.fnmatch(pattern, path, flags = 0) -> true or false
+ #
+ # Returns whether string `pattern` matches against string `path`,
+ # under the control of the given `flags`;
+ # see [Filename Matching](rdoc-ref:file/filename_matching.md).
def fnmatch(pattern, path, flags = 0)
end
alias fnmatch? fnmatch