[Fixes #15064] Calling number_to_delimited on a ActiveSupport::SafeBuffer results in mangled output

Use block parameter rather than `$1` during `gsub!` so `ActiveSupport::SafeBuffer` values aren't mangled.

Fixes #15064