Forward block argument

This commit is contained in:
Douglas Eichelberger 2023-08-04 16:18:54 -07:00
parent efd02b956d
commit 864f31e52a
2 changed files with 7 additions and 3 deletions

View File

@ -2559,10 +2559,11 @@ class Formula
before: T.nilable(T.any(Pathname, Regexp, String)),
after: T.nilable(T.any(Pathname, String, Symbol)),
audit_result: T::Boolean,
blk: T.nilable(T.proc.params(s: StringInreplaceExtension).void),
).void
}
def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
Utils::Inreplace.inreplace(paths, before, after, audit_result: audit_result)
def inreplace(paths, before = nil, after = nil, audit_result = true, &blk) # rubocop:disable Style/OptionalBooleanParameter
Utils::Inreplace.inreplace(paths, before, after, audit_result: audit_result, &blk)
rescue Utils::Inreplace::Error => e
onoe e.to_s
raise BuildError.new(self, "inreplace", Array(paths), {})

View File

@ -41,9 +41,10 @@ module Utils
before: T.nilable(T.any(Pathname, Regexp, String)),
after: T.nilable(T.any(Pathname, String, Symbol)),
audit_result: T::Boolean,
blk: T.nilable(T.proc.params(s: StringInreplaceExtension).void),
).void
}
def self.inreplace(paths, before = nil, after = nil, audit_result: true)
def self.inreplace(paths, before = nil, after = nil, audit_result: true, &blk)
paths = Array(paths)
after &&= after.to_s
before = before.to_s if before.is_a?(Pathname)
@ -57,6 +58,8 @@ module Utils
s = StringInreplaceExtension.new(str)
if before.nil? && after.nil?
raise ArgumentError, "Must supply a block or before/after params" unless blk
yield s
else
s.gsub!(T.must(before), T.must(after), audit_result)