Method: String#match!
- Defined in:
- lib/mini_sanity/match.rb
#match!(pattern, pos = 0) ⇒ MatchData
Like String#match, but raises an exception if the match fails.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mini_sanity/match.rb', line 20 def match!(pattern, pos = 0) result = self.match(pattern, pos) if result.nil? raise MiniSanity::Error.new("String does not match pattern", { "String" => self.inspect, "Relevant portion (from position #{pos})" => (self[pos..].inspect if pos != 0), "Pattern" => pattern.inspect, }) end result end |