A state that encapsulates a set of {#requirements} with an {Array} of possibilities
A state that encapsulates a single possibility to fulfill the given {#requirement}
@!visibility private
Provides information about specifications and dependencies to the resolver, allowing the {Resolver} class to remain generic while still providing power and flexibility.
This module contains the methods that users of Gem::Resolver::Molinillo
must to implement, using knowledge of their own model classes.
@!visibility private @see DependencyGraph#detach_vertex_named
Delegates
all {Gem::Resolver::Molinillo::ResolutionState} methods to a ‘#state` property.
Delegates
all {Gem::Resolver::Molinillo::SpecificationProvider} methods to a ‘#specification_provider` property.
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:
*
Matches any file. Can be restricted by other values in the glob. Equivalent to / .* /x
in regexp.
*
Matches all files regular files
c*
Matches all files beginning with c
*c
Matches all files ending with c
*c*
Matches all files that have c
in them (including at the beginning or end).
To match hidden files (that start with a .
set the File::FNM_DOTMATCH flag.
**
Matches directories recursively or files expansively.
?
Matches any one character. Equivalent to /.{1}/
in regexp.
[set]
Matches any one character in set
. Behaves exactly like character sets in Regexp
, including set negation ([^a-z]
).
\
Escapes the next metacharacter.
{a,b}
Matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled. Behaves like a Regexp
union ((?:a|b)
).
flags
is a bitwise OR of the FNM_XXX
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 rbfiles = '**' '/' '*.rb' # you don't have to do like this. just write in single string. File.fnmatch(rbfiles, 'main.rb') #=> false File.fnmatch(rbfiles, './main.rb') #=> false File.fnmatch(rbfiles, '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 pattern = '*' '/' '*' File.fnmatch(pattern, 'dave/.profile', File::FNM_PATHNAME) #=> false File.fnmatch(pattern, 'dave/.profile', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true pattern = '**' '/' 'foo' File.fnmatch(pattern, 'a/b/c/foo', File::FNM_PATHNAME) #=> true File.fnmatch(pattern, '/a/b/c/foo', File::FNM_PATHNAME) #=> true File.fnmatch(pattern, 'c:/a/b/c/foo', File::FNM_PATHNAME) #=> true File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME) #=> false File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH) #=> true
Returns a Matchdata object (or nil
) based on self
and the given pattern
.
Note: also updates Regexp-related global variables.
Computes regexp
by converting pattern
(if not already a Regexp).
regexp = Regexp.new(pattern)
Computes matchdata
, which will be either a MatchData object or nil
(see Regexp#match
):
matchdata = <tt>regexp.match(self)
With no block given, returns the computed matchdata
:
'foo'.match('f') # => #<MatchData "f"> 'foo'.match('o') # => #<MatchData "o"> 'foo'.match('x') # => nil
If Integer argument offset
is given, the search begins at index offset
:
'foo'.match('f', 1) # => nil 'foo'.match('o', 1) # => #<MatchData "o">
With a block given, calls the block with the computed matchdata
and returns the block’s return value:
'foo'.match(/o/) {|matchdata| matchdata } # => #<MatchData "o"> 'foo'.match(/x/) {|matchdata| matchdata } # => nil 'foo'.match(/f/, 1) {|matchdata| matchdata } # => nil
Returns true
or false
based on whether a match is found for self
and pattern
.
Note: does not update Regexp-related global variables.
Computes regexp
by converting pattern
(if not already a Regexp).
regexp = Regexp.new(pattern)
Returns true
if self+.match(regexp)
returns a Matchdata object, false
otherwise:
'foo'.match?(/o/) # => true 'foo'.match?('o') # => true 'foo'.match?(/x/) # => false
If Integer argument offset
is given, the search begins at index offset
:
'foo'.match?('f', 1) # => false 'foo'.match?('o', 1) # => true
Returns a MatchData
object describing the match, or nil
if there was no match. This is equivalent to retrieving the value of the special variable $~
following a normal match. If the second parameter is present, it specifies the position in the string to begin the search.
/(.)(.)(.)/.match("abc")[2] #=> "b" /(.)(.)/.match("abc", 1)[2] #=> "c"
If a block is given, invoke the block with MatchData
if match succeed, so that you can write
/M(.*)/.match("Matz") do |m| puts m[0] puts m[1] end
instead of
if m = /M(.*)/.match("Matz") puts m[0] puts m[1] end
The return value is a value from block execution in this case.
Returns a true
or false
indicates whether the regexp is matched or not without updating $~ and other related variables. If the second parameter is present, it specifies the position in the string to begin the search.
/R.../.match?("Ruby") #=> true /R.../.match?("Ruby", 1) #=> false /P.../.match?("Ruby") #=> false $& #=> nil
Returns sym.to_s.match
.
Returns sym.to_s.match?
.
Tests whether the given pattern
is matched from the current scan pointer. Returns the length of the match, or nil
. The scan pointer is not advanced.
s = StringScanner.new('test string') p s.match?(/\w+/) # -> 4 p s.match?(/\w+/) # -> 4 p s.match?("test") # -> 4 p s.match?(/\s+/) # -> nil
Returns true
if and only if the last match was successful.
s = StringScanner.new('test string') s.match?(/\w+/) # => 4 s.matched? # => true s.match?(/\d+/) # => nil s.matched? # => false
Returns the last matched string.
s = StringScanner.new('test string') s.match?(/\w+/) # -> 4 s.matched # -> "test"
The first form returns the MatchData
object generated by the last successful pattern match. Equivalent to reading the special global variable $~
(see Special global variables in Regexp
for details).
The second form returns the nth field in this MatchData
object. n can be a string or symbol to reference a named capture.
Note that the last_match
is local to the thread and method scope of the method that did the pattern match.
/c(.)t/ =~ 'cat' #=> 0 Regexp.last_match #=> #<MatchData "cat" 1:"a"> Regexp.last_match(0) #=> "cat" Regexp.last_match(1) #=> "a" Regexp.last_match(2) #=> nil /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ "var = val" Regexp.last_match #=> #<MatchData "var = val" lhs:"var" rhs:"val"> Regexp.last_match(:lhs) #=> "var" Regexp.last_match(:rhs) #=> "val"
Returns the size of the most recent match in bytes, or nil
if there was no recent match. This is different than matched.size
, which will return the size in characters.
s = StringScanner.new('test string') s.check /\w+/ # -> "test" s.matched_size # -> 4 s.check /\d+/ # -> nil s.matched_size # -> nil
Returns the pre-match
(in the regular expression sense) of the last scan.s = StringScanner.new('test string') s.scan(/\w+/) # -> "test" s.scan(/\s+/) # -> " " s.pre_match # -> "test" s.post_match # -> "string"
Returns the post-match
(in the regular expression sense) of the last scan.s = StringScanner.new('test string') s.scan(/\w+/) # -> "test" s.scan(/\s+/) # -> " " s.pre_match # -> "test" s.post_match # -> "string"
Returns the portion of the original string before the current match. Equivalent to the special variable $`
.
m = /(.)(.)(\d+)(\d)/.match("THX1138.") m.pre_match #=> "T"
Returns the portion of the original string after the current match. Equivalent to the special variable $'
.
m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") m.post_match #=> ": The Movie"