Monday, May 28, 2007

Index Ruby Objects by an Attribute


class Array
def hash_by(attribute)
self.inject({}) do |hash, e|
hash[e.send(attribute)] = e
hash
end
end
end

No comments: