Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
String#gsub
(::Regexp | ::string pattern, ::string | ::hash[::String, ::_ToS] replacement) -> ::String
(::Regexp | ::string pattern) -> ::Enumerator[::String, ::String]
(::Regexp | ::string pattern) { (::String match) -> ::_ToS } -> ::String
gsub(pattern, replacement) → new_string
gsub(pattern) {|match| ... } → new_string
gsub(pattern) → enumerator
string.c
View on GitHub ↗
static VALUE
rb_str_gsub(int argc, VALUE *argv, VALUE str)
{
return str_gsub(argc, argv, str, 0);
}
Returns a copy of self with all occurrences of the given pattern replaced.
See Substitution Methods.
Returns an Enumerator if no replacement and no block given.
Related: String#sub, String#sub!, String#gsub!.
Ruby version changes
-
3.0
-
The following methods now return or yield
Stringinstances instead of subclass instances when called on subclass instances: [Bug #10845]
-