def replace_placeholders(str, *substitutions)
named = {}
named = substitutions.pop if substitutions.last.kind_of?(Hash)
if str =~ /['"`]/
count = 0
str = str.scan(OUTSIDE_QUOTES_REGEX).
map do |(before, quoted, after)|
(before, after) = [before, after].map do |s|
s, count =
replace_placeholders_outside_quotes(s, count, substitutions, named)
s
end
[before, quoted, after].join
end.join
else
str, count =
replace_placeholders_outside_quotes(str, 0, substitutions, named)
end
raise ArgumentError.new("extra value(s): #{substitutions.inspect}") unless
substitutions.empty?
str
end