Method: String#sub

Defined in:
string.c

#sub(pattern, replacement) ⇒ Object #sub(pattern) {|match| ... } ⇒ Object

Returns a copy of self with only the first occurrence (not all occurrences) of the given pattern replaced.

See Substitution Methods.

Related: String#sub!, String#gsub, String#gsub!.

Overloads:

  • #sub(pattern) {|match| ... } ⇒ Object

    Yields:



6284
6285
6286
6287
6288
6289
6290
# File 'string.c', line 6284

static VALUE
rb_str_sub(int argc, VALUE *argv, VALUE str)
{
    str = str_duplicate(rb_cString, str);
    rb_str_sub_bang(argc, argv, str);
    return str;
}