Project

General

Profile

Actions

Feature #10927

open

[PATCH] Add default empty string to string replacements

Added by zimbatm (zimba tm) over 9 years ago. Updated over 9 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:68377]

Description

Hi ruby devs !

A common case for string substitution is to just remove the found items. This patch changes the String#[g]sub[!] methods to allow that.

Old usages:

"foo".sub("o", "") #=> "fo"
"foo".gsub("o", "") #=> "f"

New usages:

"foo".sub("o") #=> "fo"
"foo".gsub("o") #=> "f"

Applies to the bang versions as well.

This commit changes the return values of String#gsub! call with a single
argument and no block from an Enumerator to a String. The previous usage
would return an Enumerator containing each match, which is not a string
substitution. A suitable replacement should nonetheless be found before
merging this commit.

Before:

"foo".gsub("o") #=> #<Enumerator: "foo":gsub("o")>

Replacement:

???

Files

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0