[前][次][番号順一覧][スレッド一覧]

ruby-changes:68273

From: Jeremy <ko1@a...>
Date: Wed, 6 Oct 2021 00:40:58 +0900 (JST)
Subject: [ruby-changes:68273] c6706f15af (master): Fix documentation for String#{<<, concat, prepend}

https://git.ruby-lang.org/ruby.git/commit/?id=c6706f15af

From c6706f15af123bdbb3b39a21903d85c78462d047 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Tue, 5 Oct 2021 08:39:27 -0700
Subject: Fix documentation for String#{<<,concat,prepend}

These methods mutate and return the receiver, they don't create
and return a new string.

Fixes [Bug #18241]
---
 string.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/string.c b/string.c
index 1f143853e4..f95722b8d4 100644
--- a/string.c
+++ b/string.c
@@ -3171,13 +3171,13 @@ rb_str_concat_literals(size_t num, const VALUE *strary) https://github.com/ruby/ruby/blob/trunk/string.c#L3171
 
 /*
  *  call-seq:
- *     string.concat(*objects) -> new_string
+ *     string.concat(*objects) -> string
  *
- *  Returns a new \String containing the concatenation
- *  of +self+ and all objects in +objects+:
+ *  Concatenates each object in +objects+ to +self+ and returns +self+:
  *
  *    s = 'foo'
  *    s.concat('bar', 'baz') # => "foobarbaz"
+ *    s                      # => "foobarbaz"
  *
  *  For each given object +object+ that is an \Integer,
  *  the value is considered a codepoint and converted to a character before concatenation:
@@ -3209,12 +3209,13 @@ rb_str_concat_multi(int argc, VALUE *argv, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L3209
 
 /*
  *  call-seq:
- *    string << object -> str
+ *    string << object -> string 
+ *
+ *  Concatenates +object+ to +self+ and returns +self+:
  *
- *  Returns a new \String containing the concatenation
- *  of +self+ and +object+:
  *    s = 'foo'
  *    s << 'bar' # => "foobar"
+ *    s          # => "foobar"
  *
  *  If +object+ is an \Integer,
  *  the value is considered a codepoint and converted to a character before concatenation:
@@ -3289,12 +3290,12 @@ rb_str_concat(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L3290
 
 /*
  *  call-seq:
- *    string.prepend(*other_strings)  -> str
+ *    string.prepend(*other_strings)  -> string
  *
- *  Returns a new \String containing the concatenation
- *  of all given +other_strings+ and +self+:
+ *  Prepends each string in +other_strings+ to +self+ and returns +self+:
  *    s = 'foo'
  *    s.prepend('bar', 'baz') # => "barbazfoo"
+ *    s                       # => "barbazfoo"
  *
  *  Related: String#concat.
  */
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]