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:
Post Comments (Atom)
class Array
def hash_by(attribute)
self.inject({}) do |hash, e|
hash[e.send(attribute)] = e
hash
end
end
end
0 comments:
Post a Comment