Tengo una matriz que se ve así
a = ["red apple juice", "red mango juice", "red berry juice" "red fish juice", black berry juice, black potato juice, yellow bananen juice, yellow ananas juice, yellow onion juice,y me gustaria tener
{red => 4, black => 2, yellow => 3}Use Enumerable#tally :
a = [ "red apple juice", "red mango juice", "red berry juice", "red fish juice", "black berry juice", "black potato juice", "yellow bananen juice", "yellow ananas juice", "yellow onion juice" ] a.map {|s| s.split.first.to_sym }.tally # => {:red=>3, :black=>2, :yellow=>3}