From: Intransition Date: 2009-11-11T00:49:04+09:00 Subject: Re: Hash#count On Nov 9, 5:13 am, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Hash#count" >     on Thu, 5 Nov 2009 01:19:13 +0900, Intransition writes: > > |Current: > | > |  {:a=>1,:b=2,:c=>1}.count([:a,1]) #=> 1 > |  {:x=>1,:b=2,:c=>1}.count([:a,1]) #=> 0 > |  {:a=>1,:b=2,:c=>1}.count(1)      #=> 0 > | > |Proposed: > | > |  {:a=>1,:b=2,:c=>1}.count(1) #=> 2 > |  {:x=>1,:b=2,:c=>1}.count(1) #=> 2 > | > |It would be more useful that way. > > That is based on viewpoint to see hashes are collections of values > indexed by arbitrary object.  But in reality, Ruby hashes are designed > as collections of key-value pair.  I am not particularly against the > object-indexed view, but I am not going to change the existing method > behavior. Okay. I only point out, if Hash is a collection key-value pairs, I would expect Hash#include? to check pairs too. Personally I like to see methods behave according to most common uses, not an abstract viewpoint. I realize that is not always easy to determine (YMMV and all that), but I think it's a worthy pursuit nonetheless. > |And, in the same vain, a #has_pair? > |seems like an obvious addition. > > Let's address the issue one by one. Sure.