Sha256: d0cbb5724d9eb71c99dfe59b8afd99e8c878f92c34ebcdbe9f13f9ed5d7d9b22
Contents?: true
Size: 514 Bytes
Versions: 373
Compression:
Stored size: 514 Bytes
Contents
# frozen_string_literal: true class Regexp # 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. 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 end
Version data entries
373 entries across 373 versions & 4 rubygems