summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorBurdette Lamar <BurdetteLamar@Yahoo.com>2022-03-09 19:53:51 -0600
committerGitHub <noreply@github.com>2022-03-09 19:53:51 -0600
commit561dda99344536cb281b5a55c48856d3dae717c6 (patch)
tree17f95d541429010b1c24b8d6ccf755700c919cd9 /string.c
parentee5bf4cac2a4244d8b4b93d3b5f60521e56a16ad (diff)
downloadruby-561dda99344536cb281b5a55c48856d3dae717c6.tar.gz
[DOC] Enhanced RDoc for String (#5635)
Treats: #count #delete #delete! #squeeze #squeeze! Adds section "Multiple Character Selectors" to doc/character_selectors.rdoc. Co-authored-by: Peter Zhu <peter@peterzhu.ca>
Diffstat (limited to 'string.c')
-rw-r--r--string.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/string.c b/string.c
index 3bc250122b..7ac11c31d4 100644
--- a/string.c
+++ b/string.c
@@ -8158,10 +8158,11 @@ tr_find(unsigned int c, const char table[TR_TABLE_SIZE], VALUE del, VALUE nodel)
/*
* call-seq:
- * str.delete!([other_str]+) -> str or nil
+ * delete!(*selectors) -> self or nil
+ *
+ * Like String#delete, but modifies +self+ in place.
+ * Returns +self+ if any changes were made, +nil+ otherwise.
*
- * Performs a <code>delete</code> operation in place, returning <i>str</i>, or
- * <code>nil</code> if <i>str</i> was not modified.
*/
static VALUE
@@ -8228,16 +8229,16 @@ rb_str_delete_bang(int argc, VALUE *argv, VALUE str)
/*
* call-seq:
- * str.delete([other_str]+) -> new_str
+ * delete(*selectors) -> new_string
*
- * Returns a copy of <i>str</i> with all characters in the intersection of its
- * arguments deleted. Uses the same rules for building the set of characters as
- * String#count.
+ * Returns a copy of +self+ with characters specified by +selectors+ removed
+ * (see {Multiple Character Selectors}[rdoc-ref:character_selectors.rdoc@Multiple+Character+Selectors]):
*
* "hello".delete "l","lo" #=> "heo"
* "hello".delete "lo" #=> "he"
* "hello".delete "aeiou", "^e" #=> "hell"
* "hello".delete "ej-m" #=> "ho"
+ *
*/
static VALUE
@@ -8251,10 +8252,10 @@ rb_str_delete(int argc, VALUE *argv, VALUE str)
/*
* call-seq:
- * str.squeeze!([other_str]*) -> str or nil
+ * squeeze!(*selectors) -> self or nil
*
- * Squeezes <i>str</i> in place, returning either <i>str</i>, or
- * <code>nil</code> if no changes were made.
+ * Like String#squeeze, but modifies +self+ in place.
+ * Returns +self+ if any changes were made, +nil+ otherwise.
*/
static VALUE
@@ -8335,17 +8336,19 @@ rb_str_squeeze_bang(int argc, VALUE *argv, VALUE str)
/*
* call-seq:
- * str.squeeze([other_str]*) -> new_str
+ * str.squeeze(*selectors) -> new_string
*
- * Builds a set of characters from the <i>other_str</i> parameter(s)
- * using the procedure described for String#count. Returns a new
- * string where runs of the same character that occur in this set are
- * replaced by a single character. If no arguments are given, all
- * runs of identical characters are replaced by a single character.
+ * Returns a copy of +self+ with characters specified by +selectors+ "squeezed"
+ * (see {Multiple Character Selectors}[rdoc-ref:character_selectors.rdoc@Multiple+Character+Selectors]):
+ *
+ * "Squeezed" means that each multiple-character run of a selected character
+ * is squeezed down to a single character;
+ * with no arguments given, squeezes all characters:
*
* "yellow moon".squeeze #=> "yelow mon"
* " now is the".squeeze(" ") #=> " now is the"
* "putters shoot balls".squeeze("m-z") #=> "puters shot balls"
+ *
*/
static VALUE
@@ -8400,15 +8403,11 @@ rb_str_tr_s(VALUE str, VALUE src, VALUE repl)
/*
* call-seq:
- * str.count([other_str]+) -> integer
- *
- * Each +other_str+ parameter defines a set of characters to count. The
- * intersection of these sets defines the characters to count in +str+. Any
- * +other_str+ that starts with a caret <code>^</code> is negated. The
- * sequence <code>c1-c2</code> means all characters between c1 and c2. The
- * backslash character <code>\\</code> can be used to escape <code>^</code> or
- * <code>-</code> and is otherwise ignored unless it appears at the end of a
- * sequence or the end of a +other_str+.
+ * count(*selectors) -> integer
+ *
+ * Returns the total number of characters in +self+
+ * that are specified by the given +selectors+
+ * (see {Multiple Character Selectors}[rdoc-ref:character_selectors.rdoc@Multiple+Character+Selectors]):
*
* a = "hello world"
* a.count "lo" #=> 5