--- !ruby/object:RI::MethodDescription aliases: [] block_params: comment: - !ruby/struct:SM::Flow::P body: Returns a copy of str with the first occurrence of pattern replaced with either replacement or the value of the block. The pattern will typically be a Regexp; if it is a String then no regular expression metacharacters will be interpreted (that is /\d/ will match a digit, but '\d' will match a backslash followed by a 'd'). - !ruby/struct:SM::Flow::P body: If the method call specifies replacement, special variables such as $& will not be useful, as substitution into the string occurs before the pattern match starts. However, the sequences \1, \2, etc., may be used. - !ruby/struct:SM::Flow::P body: In the block form, the current match string is passed in as a parameter, and variables such as $1, $2, $`, $&, and $' will be set appropriately. The value returned by the block will be substituted for the match on each call. - !ruby/struct:SM::Flow::P body: The result inherits any tainting in the original string or any supplied replacement string. - !ruby/struct:SM::Flow::VERB body: " "hello".sub(/[aeiou]/, '*') #=> "h*llo"\n "hello".sub(/([aeiou])/, '<\\1>') #=> "h<e>llo"\n "hello".sub(/./) {|s| s[0].to_s + ' ' } #=> "104 ello"\n" full_name: String#sub is_singleton: false name: sub params: | str.sub(pattern, replacement) => new_str str.sub(pattern) {|match| block } => new_str visibility: public