class Array
def hash_by(attribute)
self.inject({}) do |hash, e|
hash[e.send(attribute)] = e
hash
end
end
end
Monday, May 28, 2007
Index Ruby Objects by an Attribute
Subscribe to:
Posts (Atom)
class Array
def hash_by(attribute)
self.inject({}) do |hash, e|
hash[e.send(attribute)] = e
hash
end
end
end