From: Thomas Greenwood Date: 2011-05-15T19:01:09+09:00 Subject: Counting how many times the same elements occurs in an array? There's probably a fairly simple way to do this. Basically I'm reading data from an xml file, I need to figure out how many times identical data occurs in certain attributes, so far I've got the data into two identical arrays and had the intention of nesting iterators - seeing if the element was equal to the second and incrementing every time a match was found. That obviously didn't work out the way I initially thought. This seems to be the jist of what I want but it's obviously returning a count on every iteraton whereas I only want the final tally. xml_events.each{|x| puts "#{x} occurs #{xml_events.count(x)} times" } Any ideas? -- Posted via http://www.ruby-forum.com/.