[DOC] Tweaks for String#-@

This commit is contained in:
Burdette Lamar 2025-05-08 09:31:47 -05:00 committed by GitHub
parent 5e53484994
commit 46a8240884
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2025-05-08 14:32:00 +00:00
Merged: https://github.com/ruby/ruby/pull/13254

Merged-By: peterzhu2118 <peter@peterzhu.ca>

View File

@ -3615,24 +3615,37 @@ str_uplus(VALUE str)
/* /*
* call-seq: * call-seq:
* -string -> frozen_string * -self -> frozen_string
* dedup -> frozen_string
* *
* Returns a frozen, possibly pre-existing copy of the string. * Returns a frozen string equal to +self+.
* *
* The returned +String+ will be deduplicated as long as it does not have * The returned string is +self+ if and only if all of the following are true:
* any instance variables set on it and is not a String subclass.
* *
* Note that <tt>-string</tt> variant is more convenient for defining * - +self+ is already frozen.
* constants: * - +self+ is an instance of \String (rather than of a subclass of \String)
* - +self+ has no instance variables set on it.
* *
* FILENAME = -'config/database.yml' * Otherwise, the returned string is a frozen copy of +self+.
* *
* while +dedup+ is better suitable for using the method in chains * Returning +self+, when possible, saves duplicating +self+;
* of calculations: * see {Data deduplication}[https://en.wikipedia.org/wiki/Data_deduplication].
* *
* @url_list.concat(urls.map(&:dedup)) * It may also save duplicating other, already-existing, strings:
* *
* s0 = 'foo'
* s1 = 'foo'
* s0.object_id == s1.object_id # => false
* (-s0).object_id == (-s1).object_id # => true
*
* Note that method #-@ is convenient for defining a constant:
*
* FileName = -'config/database.yml'
*
* While its alias #dedup is better suited for chaining:
*
* 'foo'.dedup.gsub!('o')
*
* Related: see {Methods for a Frozen/Unfrozen String}[rdoc-ref:String@Methods+for+a+Frozen-2FUnfrozen+String].
*/ */
static VALUE static VALUE
str_uminus(VALUE str) str_uminus(VALUE str)