[DOC] Tweaks for String#-@
This commit is contained in:
parent
5e53484994
commit
46a8240884
Notes:
git
2025-05-08 14:32:00 +00:00
Merged: https://github.com/ruby/ruby/pull/13254 Merged-By: peterzhu2118 <peter@peterzhu.ca>
35
string.c
35
string.c
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user