summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authorBurdetteLamar <[email protected]>2024-08-17 19:18:32 +0100
committerPeter Zhu <[email protected]>2024-08-21 15:56:59 -0400
commit76ccd1df3777312f865f83d5fd945b18140ecb48 ()
tree3dd7f21be08526754337d4a435060a9592479b82 /enum.c
parent53e37953791921b42c3d409b23c488861094f714 (diff)
[DOC] Tweaks for Enum#tally
Notes: Merged: https://.com/ruby/ruby/pull/11399
-rw-r--r--enum.c54
1 files changed, 36 insertions, 18 deletions
@@ -1235,29 +1235,47 @@ tally_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, hash))
/*
* call-seq:
- * tally -> new_hash
- * tally(hash) -> hash
*
- * Returns a hash containing the counts of equal elements:
*
- * - Each key is an element of +self+.
- * - Each value is the number elements equal to that key.
*
- * With no argument:
*
- * %w[a b c b c a c b].tally # => {"a"=>2, "b"=>3, "c"=>3}
*
- * With a hash argument, that hash is used for the tally (instead of a new hash),
- * and is returned;
- * this may be useful for accumulating tallies across multiple enumerables:
- *
- * hash = {}
- * hash = %w[a c d b c a].tally(hash)
- * hash # => {"a"=>2, "c"=>2, "d"=>1, "b"=>1}
- * hash = %w[b a z].tally(hash)
- * hash # => {"a"=>3, "c"=>2, "d"=>1, "b"=>2, "z"=>1}
- * hash = %w[b a m].tally(hash)
- * hash # => {"a"=>4, "c"=>2, "d"=>1, "b"=>3, "z"=>1, "m"=> 1}
*
*/