mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Simplify example code for Enumerable#each_with_object
This commit is contained in:
parent
5c61caa481
commit
9e8841e592
Notes:
git
2022-04-26 04:32:58 +09:00
Merged: https://github.com/ruby/ruby/pull/5825 Merged-By: jeremyevans <code@jeremyevans.net>
1 changed files with 4 additions and 2 deletions
6
enum.c
6
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.
|
||||
|
|
Loading…
Add table
Reference in a new issue