J'ai un tableau RubyRuby: Comment grouper un tableau 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"]
et je veux une liste avec les comptes comme celui-ci:
{"Nothing Else Matters" => 1,
"Enter Sandman" => 2,
"Master of Puppets" => 3}
Donc, idéalement, je veux un hachage qui me donnera le compte et notez comment je Enter Sandman
et enter sandman
donc j'ai besoin de lui insensible à la casse. Je suis assez sûr que je peux traverser, mais y at-il une façon plus propre?
Au lieu de 'capitalize', il y a un' titlecase' snippet ici: http://snippets.dzone.com/posts/show/294 –