aboutsummaryrefslogtreecommitdiffstats
path: root/enum.c
diff options
context:
space:
mode:
authorColin Hart <colin.hart@stitchfix.com>2022-04-25 15:32:29 -0400
committerGitHub <noreply@github.com>2022-04-25 12:32:29 -0700
commit9e8841e592c40e65bbad410a490c05f07a87052e (patch)
tree8ba384a940276a17cdd7063631e2dcffef1152ba /enum.c
parent5c61caa48154e3e43ff29ab865310aa9bdd9e83a (diff)
downloadruby-9e8841e592c40e65bbad410a490c05f07a87052e.tar.gz
Simplify example code for Enumerable#each_with_object
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/enum.c b/enum.c
index bb12f18e0f..403ce45dca 100644
--- a/enum.c
+++ b/enum.c
@@ -3098,8 +3098,10 @@ each_with_object_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo))
* Calls the block once for each element, passing both the element
* and the given object:
*
- * (1..4).each_with_object([]) {|i, a| a.push(i**2) } # => [1, 4, 9, 16]
- * h.each_with_object({}) {|element, h| k, v = *element; h[v] = k }
+ * (1..4).each_with_object([]) {|i, a| a.push(i**2) }
+ * # => [1, 4, 9, 16]
+ *
+ * {foo: 0, bar: 1, baz: 2}.each_with_object({}) {|(k, v), h| h[v] = k }
* # => {0=>:foo, 1=>:bar, 2=>:baz}
*
* With no block given, returns an Enumerator.