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

Enhanced RDoc for String (#3565)

Makes some methods doc compliant with https://github.com/ruby/ruby/blob/master/doc/method_documentation.rdoc. Also, other minor revisions to make more consistent.
Methods:

    try_convert
    +string
    -string
    concat
    <<
    prepend
    hash
This commit is contained in:
Burdette Lamar 2020-09-22 16:32:17 -05:00 committed by GitHub
parent 3d474e19fd
commit b904b72960
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2020-09-23 06:32:43 +09:00
Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>

View file

@ -2384,14 +2384,16 @@ rb_check_string_type(VALUE str)
/* /*
* call-seq: * call-seq:
* String.try_convert(obj) -> string or nil * String.try_convert(object) -> object, new_string, or nil
* *
* Try to convert <i>obj</i> into a String, using to_str method. * If +object+ is a \String object, returns +object+.
* Returns converted string or nil if <i>obj</i> cannot be converted
* for any reason.
* *
* String.try_convert("str") #=> "str" * Otherwise if +object+ responds to <tt>:to_str</tt>,
* String.try_convert(/re/) #=> nil * calls <tt>object.to_str</tt> and returns the result.
*
* Returns +nil+ if +object+ does not respond to <tt>:to_str</tt>
*
* Raises an exception unless <tt>object.to_str</tt> returns a \String object.
*/ */
static VALUE static VALUE
rb_str_s_try_convert(VALUE dummy, VALUE str) rb_str_s_try_convert(VALUE dummy, VALUE str)
@ -2688,11 +2690,11 @@ rb_str_freeze(VALUE str)
/* /*
* call-seq: * call-seq:
* +str -> str (mutable) * +string -> new_string or self
* *
* If the string is frozen, then return duplicated mutable string. * Returns +self+ if +self+ is not frozen.
* *
* If the string is not frozen, then return the string itself. * Otherwise. returns <tt>self.dup</tt>, which is not frozen.
*/ */
static VALUE static VALUE
str_uplus(VALUE str) str_uplus(VALUE str)
@ -2707,11 +2709,11 @@ str_uplus(VALUE str)
/* /*
* call-seq: * call-seq:
* -str -> str (frozen) * -string -> frozen_string
* *
* Returns a frozen, possibly pre-existing copy of the string. * Returns a frozen, possibly pre-existing copy of the string.
* *
* The string will be deduplicated as long as it does not have * The returned \String will be deduplicated as long as it does not have
* any instance variables set on it. * any instance variables set on it.
*/ */
static VALUE static VALUE
@ -3075,23 +3077,20 @@ rb_str_concat_literals(size_t num, const VALUE *strary)
/* /*
* call-seq: * call-seq:
* str.concat(obj1, obj2, ...) -> str * string.concat(*objects) -> new_string
* *
* Concatenates the given object(s) to <i>str</i>. If an object is an * Returns a new \String containing the concatenation
* Integer, it is considered a codepoint and converted to a character * of +self+ and all objects in +objects+:
* before concatenation.
* *
* +concat+ can take multiple arguments, and all the arguments are * s = 'foo'
* concatenated in order. * s.concat('bar', 'baz') # => "foobarbaz"
* *
* a = "hello " * For each given object +object+ that is an \Integer,
* a.concat("world", 33) #=> "hello world!" * the value is considered a codepoint and converted to a character before concatenation:
* a #=> "hello world!" * s = 'foo'
* s.concat(32, 'bar', 32, 'baz') # => "foo bar baz"
* *
* b = "sn" * Related: String#<<, which takes a single argument.
* b.concat("_", b, "_", b) #=> "sn_sn_sn"
*
* See also String#<<, which takes a single argument.
*/ */
static VALUE static VALUE
rb_str_concat_multi(int argc, VALUE *argv, VALUE str) rb_str_concat_multi(int argc, VALUE *argv, VALUE str)
@ -3116,18 +3115,19 @@ rb_str_concat_multi(int argc, VALUE *argv, VALUE str)
/* /*
* call-seq: * call-seq:
* str << obj -> str * string << object -> str
* str << integer -> str
* *
* Appends the given object to <i>str</i>. If the object is an * Returns a new \String containing the concatenation
* Integer, it is considered a codepoint and converted to a character * of +self+ and +object+:
* before being appended. * s = 'foo'
* s << 'bar' # => "foobar"
* *
* a = "hello " * If +object+ is an \Integer,
* a << "world" #=> "hello world" * the value is considered a codepoint and converted to a character before concatenation:
* a << 33 #=> "hello world!" * s = 'foo'
* s << 33 # => "foo!"
* *
* See also String#concat, which takes multiple arguments. * Related: String#concat, which takes multiple arguments.
*/ */
VALUE VALUE
rb_str_concat(VALUE str1, VALUE str2) rb_str_concat(VALUE str1, VALUE str2)
@ -3195,15 +3195,14 @@ rb_str_concat(VALUE str1, VALUE str2)
/* /*
* call-seq: * call-seq:
* str.prepend(other_str1, other_str2, ...) -> str * string.prepend(*other_strings) -> str
* *
* Prepend---Prepend the given strings to <i>str</i>. * Returns a new \String containing the concatenation
* of all given +other_strings+ and +self+:
* s = 'foo'
* s.prepend('bar', 'baz') # => "barbazfoo"
* *
* a = "!" * Related: String#concat.
* a.prepend("hello ", "world") #=> "hello world!"
* a #=> "hello world!"
*
* See also String#concat.
*/ */
static VALUE static VALUE
@ -3251,11 +3250,10 @@ rb_str_hash_cmp(VALUE str1, VALUE str2)
/* /*
* call-seq: * call-seq:
* str.hash -> integer * string.hash -> integer
* *
* Returns a hash based on the string's length, content and encoding. * Returns the integer hash value for +self+.
* * The value is based on the length, content and encoding of +self+.
* See also Object#hash.
*/ */
static VALUE static VALUE