Skip to content

Commit

Permalink
Added each_with_object example
Browse files Browse the repository at this point in the history
  • Loading branch information
alebian committed May 17, 2016
1 parent 06092e6 commit ac52cfc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If you keep your house cleaned constantly you'll never need to waste a weekend c

## Contributors

A big thanks to the following [persons](https://github.com/franzejr/best-ruby/graphs/contributors)
A big thanks to the following [people](https://github.com/franzejr/best-ruby/graphs/contributors)

## Contributing

Expand Down
9 changes: 9 additions & 0 deletions idiomatic_ruby/combine_elements_in_collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ values.inject({}) do |hash, value|
end
# => { 1 => 1, 2 => 4, 3 => 9, 4 => 16 }
```

Or with the `each_with_object` method:

```ruby
values.each_with_object({}) do |value, hash|
hash[value] = value ** 2
end
# => { 1 => 1, 2 => 4, 3 => 9, 4 => 16 }
```

0 comments on commit ac52cfc

Please sign in to comment.