method
index_with
v6.0.0 -
Show latest stable
- Class:
Enumerable
index_with(default = INDEX_WITH_DEFAULT)public
Convert an enumerable to a hash keying it with the enumerable items and with the values returned in the block.
post = Post.new(title: "hey there", body: "what's up?") %i( title body ).index_with { |attr_name| post.public_send(attr_name) } # => { title: "hey there", body: "what's up?" }