From: "David A. Black" Date: 2009-10-05T21:36:16+09:00 Subject: Re: Count the number of times an element occurs in an array Hi -- On Mon, 5 Oct 2009, Jim Burgess wrote: > Cheers for the replies, they are certainly very interesting and I will > work through all of them. > However, now I'm having weird problem. > > When I run the following on Linux: > a = ["a", "b", "a", "b", "b"] > > a.uniq.each do |elem| > puts "#{elem}\t#{a.count(elem)}" > end > > I get the expected output : > a 2 > b 3 > > But when I run exactly the same code on Windows I get: > > undefined method `count' for ["a", "b", "a", "b", "b"]:Array > (NoMethodError) > > ruby -v (Linux): ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux] > ruby -v (Windows): ruby 1.8.6 (2009-09-24 patchlevel 111) [i386-mswin32] > > Does anyone have an idea why this could be happening. > I have tried searching for a solution with Google, but could find > nothing helpful. count is a post-1.8.6 method. David -- David A. Black, Director Ruby Power and Light, LLC (http://www.rubypal.com) Ruby/Rails training, consulting, mentoring, code review Book: The Well-Grounded Rubyist (http://www.manning.com/black2)