Forward block argument
This commit is contained in:
parent
efd02b956d
commit
864f31e52a
@ -2559,10 +2559,11 @@ class Formula
|
|||||||
before: T.nilable(T.any(Pathname, Regexp, String)),
|
before: T.nilable(T.any(Pathname, Regexp, String)),
|
||||||
after: T.nilable(T.any(Pathname, String, Symbol)),
|
after: T.nilable(T.any(Pathname, String, Symbol)),
|
||||||
audit_result: T::Boolean,
|
audit_result: T::Boolean,
|
||||||
|
blk: T.nilable(T.proc.params(s: StringInreplaceExtension).void),
|
||||||
).void
|
).void
|
||||||
}
|
}
|
||||||
def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
|
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)
|
Utils::Inreplace.inreplace(paths, before, after, audit_result: audit_result, &blk)
|
||||||
rescue Utils::Inreplace::Error => e
|
rescue Utils::Inreplace::Error => e
|
||||||
onoe e.to_s
|
onoe e.to_s
|
||||||
raise BuildError.new(self, "inreplace", Array(paths), {})
|
raise BuildError.new(self, "inreplace", Array(paths), {})
|
||||||
|
|||||||
@ -41,9 +41,10 @@ module Utils
|
|||||||
before: T.nilable(T.any(Pathname, Regexp, String)),
|
before: T.nilable(T.any(Pathname, Regexp, String)),
|
||||||
after: T.nilable(T.any(Pathname, String, Symbol)),
|
after: T.nilable(T.any(Pathname, String, Symbol)),
|
||||||
audit_result: T::Boolean,
|
audit_result: T::Boolean,
|
||||||
|
blk: T.nilable(T.proc.params(s: StringInreplaceExtension).void),
|
||||||
).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)
|
paths = Array(paths)
|
||||||
after &&= after.to_s
|
after &&= after.to_s
|
||||||
before = before.to_s if before.is_a?(Pathname)
|
before = before.to_s if before.is_a?(Pathname)
|
||||||
@ -57,6 +58,8 @@ module Utils
|
|||||||
s = StringInreplaceExtension.new(str)
|
s = StringInreplaceExtension.new(str)
|
||||||
|
|
||||||
if before.nil? && after.nil?
|
if before.nil? && after.nil?
|
||||||
|
raise ArgumentError, "Must supply a block or before/after params" unless blk
|
||||||
|
|
||||||
yield s
|
yield s
|
||||||
else
|
else
|
||||||
s.gsub!(T.must(before), T.must(after), audit_result)
|
s.gsub!(T.must(before), T.must(after), audit_result)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user