Possible Duplicate:
count duplicate elements in ruby array
I just started learning ruby and I wish to achieve something like this.
Let say I have an array
["student", "student", "teacher", "teacher", "teacher"]
What I’m trying to do is to count the number of student and teacher and store it into a hash, so that i can get
{:student= > 2, :teacher=> 3}
Could someone give me some kind of direction on how to do this?
You should check this answer, which gives this example: