module Dieses::Support::Hash

Public Instance Methods

hashify_by(array_of_objects, attribute) click to toggle source
# File lib/dieses/support/hash.rb, line 6
def hashify_by(array_of_objects, attribute)
  {}.tap do |hash|
    array_of_objects.each do |object|
      hash[object.send(attribute)] = object
    rescue NoMethodError
      raise ArgumentError, "Object not respond to #{attribute}: #{object}"
    end
  end
end