[ci skip] Add documentation/changelog entry.

上级 39c22303
* Add `index_with` to Enumerable.
Allows creating a hash from an enumerable with the value from a passed block
or a default argument.
%i( title body ).index_with { |attr| post.public_send(attr) }
# => { title: "hey", body: "what's up?" }
%i( title body ).index_with(nil)
# => { title: nil, body: nil }
Closely linked with its brethen `index_by`.
*Kasper Timm Hansen*
* Fix bug where `ActiveSupport::Timezone.all` would fail when tzinfo data for
any timezone defined in `ActiveSupport::TimeZone::MAPPING` is missing.
......
......@@ -2039,6 +2039,21 @@ WARNING. Keys should normally be unique. If the block returns the same value for
NOTE: Defined in `active_support/core_ext/enumerable.rb`.
### `index_with`
The method `index_with` generates a hash with the elements of an enumerable as keys. The value
is either a passed default or returned in a block.
```ruby
%i( title body created_at ).index_with { |attr_name| public_send(attr_name) }
# => { title: "hey", body: "what's up?", … }
WEEKDAYS.index_with([ Interval.all_day ])
# => { monday: [ 0, 1440 ], … }
```
NOTE: Defined in `active_support/core_ext/enumerable.rb`.
### `many?`
The method `many?` is shorthand for `collection.size > 1`:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册