1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[DOC] Improve docs for String#match

Fix invalid code to make it syntax highlighted; other small fixes.
This commit is contained in:
Marcus Stollsteimer 2020-01-08 20:53:31 +01:00
parent 841a945d63
commit 1d09acd82b

View file

@ -3831,9 +3831,9 @@ static VALUE get_pat(VALUE);
* str.match(pattern, pos) -> matchdata or nil * str.match(pattern, pos) -> matchdata or nil
* *
* Converts <i>pattern</i> to a Regexp (if it isn't already one), * Converts <i>pattern</i> to a Regexp (if it isn't already one),
* then invokes its <code>match</code> method on <i>str</i>. If the second * then invokes its <code>match</code> method on the receiver.
* parameter is present, it specifies the position in the string to begin the * If the second parameter is present, it specifies the position
* search. * in the string to begin the search.
* *
* 'hello'.match('(.)\1') #=> #<MatchData "ll" 1:"l"> * 'hello'.match('(.)\1') #=> #<MatchData "ll" 1:"l">
* 'hello'.match('(.)\1')[0] #=> "ll" * 'hello'.match('(.)\1')[0] #=> "ll"
@ -3841,18 +3841,18 @@ static VALUE get_pat(VALUE);
* 'hello'.match(/(.)\1/, 3) #=> nil * 'hello'.match(/(.)\1/, 3) #=> nil
* 'hello'.match('xx') #=> nil * 'hello'.match('xx') #=> nil
* *
* If a block is given, invoke the block with MatchData if match succeed, so * If a block is given, invokes the block with MatchData if match succeeds,
* that you can write * so that you can write
* *
* str.match(pat) {|m| ...} * str.match(pat) {|m| block }
* *
* instead of * instead of
* *
* if m = str.match(pat) * if m = str.match(pat)
* ... * # ...
* end * end
* *
* The return value is a value from block execution in this case. * The return value in this case is the value from block execution.
*/ */
static VALUE static VALUE