method

index_with

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?" }