From: Christoph Date: 2002-07-15T00:34:14+09:00 Subject: RE: hey! where's #count? > -----Original Message----- > From: Philipp Meier [mailto:meier@meisterbohne.de] > Sent: Sunday, July 14, 2002 5:20 PM > To: ruby-talk ML > Subject: Re: hey! where's #count? > > On Sun, Jul 14, 2002 at 11:41:55PM +0900, Christoph wrote: > > > The problem is that some Enumerable classes like the Hash class or > > a Set class (see for example rough/lib/set.rb - OT I am not sure why > > this implementation doesn't include Comparable) don't know the > > about the idea of multiple occurrences consequently you would > > optimize #count to > > > > def count(c) > > each {|e| return 1 if e == c } > > return 0 > > end > > > > which is sort of an indication (to me) that #count doesn't really into > > Enumerable ... > > Considering Enumerables like Set or Hash as a degenerated Enumerable I > find #count makes sense in Enumberable. Hash or Set can easily provide > optimized versions of #count. It like find for a sorted list which can True - I guess my point was that the Hash/Set degeneration is so common, that it is hard to speak(write) about "degeneration". /Christoph