Linux heracles.o2switch.net 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
/
opt
/
alt
/
ruby21
/
share
/
ri
/
2.1.0
/
system
/
String
/
//opt/alt/ruby21/share/ri/2.1.0/system/String/sub-i.ri
U:RDoc::AnyMethod[iI"sub:ETI"String#sub;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [ I"FReturns a copy of +str+ with the _first_ occurrence of +pattern+ ;TI"Nreplaced by the second argument. The +pattern+ is typically a Regexp; if ;TI"Ogiven as a String, any regular expression metacharacters it contains will ;TI"Nbe interpreted literally, e.g. <code>'\\\d'</code> will match a backlash ;TI")followed by 'd', instead of a digit.;To:RDoc::Markup::BlankLine o; ; [I"OIf +replacement+ is a String it will be substituted for the matched text. ;TI"PIt may contain back-references to the pattern's capture groups of the form ;TI"><code>"\\d"</code>, where <i>d</i> is a group number, or ;TI"G<code>"\\k<n>"</code>, where <i>n</i> is a group name. If it is a ;TI"Gdouble-quoted string, both back-references must be preceded by an ;TI"Kadditional backslash. However, within +replacement+ the special match ;TI"Nvariables, such as <code>&$</code>, will not refer to the current match. ;TI"PIf +replacement+ is a String that looks like a pattern's capture group but ;TI"Nis actaully not a pattern capture group e.g. <code>"\\'"</code>, then it ;TI"Nwill have to be preceded by two backslashes like so <code>"\\\\'"</code>.;T@o; ; [I"PIf the second argument is a Hash, and the matched text is one of its keys, ;TI"7the corresponding value is the replacement string.;T@o; ; [ I"NIn the block form, the current match string is passed in as a parameter, ;TI"Nand variables such as <code>$1</code>, <code>$2</code>, <code>$`</code>, ;TI"O<code>$&</code>, and <code>$'</code> will be set appropriately. The value ;TI"Jreturned by the block will be substituted for the match on each call.;T@o; ; [I"MThe result inherits any tainting in the original string or any supplied ;TI"replacement string.;T@o:RDoc::Markup::Verbatim; [I">"hello".sub(/[aeiou]/, '*') #=> "h*llo" ;TI"@"hello".sub(/([aeiou])/, '<\1>') #=> "h<e>llo" ;TI"A"hello".sub(/./) {|s| s.ord.to_s + ' ' } #=> "104 ello" ;TI"@"hello".sub(/(?<foo>[aeiou])/, '*\k<foo>*') #=> "h*e*llo" ;TI"B'Is SHELL your preferred shell?'.sub(/[[:upper:]]{2,}/, ENV) ;TI". #=> "Is /bin/bash your preferred shell?";T:@format0: @fileI" string.c;T:0@omit_headings_from_table_of_contents_below0I"�str.sub(pattern, replacement) -> new_str str.sub(pattern, hash) -> new_str str.sub(pattern) {|match| block } -> new_str ;T0[ I"(*args);T@5FI"String;TcRDoc::NormalClassI" scanf;T0