Tengo una matriz de RubyRuby: ¿Cómo agrupar una matriz de Ruby?
> list = Request.find_all_by_artist("Metallica").map(&:song)
=> ["Nothing else Matters", "Enter sandman", "Enter Sandman", "Master of Puppets", "Master of Puppets", "Master of Puppets"]
y quiero una lista con los conteos de esta manera:
{"Nothing Else Matters" => 1,
"Enter Sandman" => 2,
"Master of Puppets" => 3}
De manera ideal, quiero un hash que me dará el conteo y notar cómo tengo Enter Sandman
y enter sandman
, así que lo necesito sin distinción de mayúsculas y minúsculas. Estoy bastante seguro de que puedo recorrerlo pero ¿hay una manera más limpia?
en lugar de 'capitalize', hay un' titlecase' snippet aquí: http://snippets.dzone.com/posts/show/294 –