>a = ["a", "b", "a", "b", "b"]
>a.uniq.each do |elem|
>  puts "#{elem}\t#{a.count(elem)}"
>end

@Fleck Jean-Julien
Thanks for the quick fix. That works perfectly and is miles better than 
what I wrote.

@Ryan
Thanks for the suggestions.

> Your indentation is wack. Make sure you're not mixing spaces and tabs.
> 2 spaces per indent. You're mixing 2 & 3 & possibly tabs at 8.
Sorry about that. I'm writing ruby in a virtual Windows on a Linux host.
Formatting got a bit corrupted when copying the code. I'll watch out for 
that next time.

> Your variable names are meaningless. Improve that and you'll have a
> lot better time debugging when it is 4am and you're tired.
Sorry. I just did that to make the example easier. In reality they are 
called things like '@had_lessons_all' and '@had_lessons_number'.

> You're not using (sensible) iterators. I suggest you read that section
> in the pickaxe book.
Good tip. I will do that now.

> You're not using good data structures or algorithms. 
No kidding :-)

> count = Hash.new 0
> 
> # iterate over each string only once
> strings.each do |string|
>    # increment the count for each string
>    count[string] += 1
> end
> 
> p count

Thanks for that. I will try to rewrite my method (for the sake of 
learning) in a neater way, using the technique you suggest.

Cheers

-- 
Posted via http://www.ruby-forum.com/.