class Regexp
Public Instance Methods
if_match(string, required = true, &block)
click to toggle source
If self
matches string
returns +block.call(Match result) or only Match result if block is not provided. If self
does not match string
raises a ArgumentError
if required
is truthy or return nil
otherwise.
# File lib/eac_ruby_utils/patches/regexp/if_match.rb, line 8 def if_match(string, required = true, &block) m = match(string) if m block ? block.call(m) : m elsif required raise(::ArgumentError, "Pattern \"#{self}\" does not match string \"#{string}\"") end end
to_parser(&block)
click to toggle source
@return [::EacRubyUtils::RegexpParser]
# File lib/eac_ruby_utils/patches/regexp/to_parser.rb, line 7 def to_parser(&block) ::EacRubyUtils::RegexpParser.new(self, &block) end