method
index_by
Ruby on Rails latest stable (v7.1.3.2)
-
0 notes -
Class: Enumerable
index_by()
public
Convert an enumerable to a hash, using the block result as the key and the element as the value.
people.index_by(&:login) # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...} people.index_by { |person| "#{person.first_name} #{person.last_name}" } # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}