From: ara.t.howard@... Date: 2006-12-27T05:45:35+09:00 Subject: Re: Hash with two identical keys? On Wed, 27 Dec 2006, Trans wrote: >> From Facets' multiton.rb (which is primarily Floran Franks' work), I'm > getting somthing that doesn't make any sense: > > POOLS[self] ||= {} > p POOLS[self].class > p POOLS[self].keys > > Is outputing: > > Hash > [[{:strip_comments=>false}], [{:strip_comments=>false}]] > > How can two identical keys be in a hash? > > T. hi trans- afaik multiton.rb is mine http://codeforpeople.com/lib/ruby/multiton/multiton-1.0.2/lib/multiton.rb the logic behind POOLS is that objects are cached this way POOLS[ class_of_object ][ args_given_to_new ] = obj in otherwords, contructing two objects with the same argument lists will contruct only one object. it's the argument lists which are used to determine uniqueness. alternatively uniqueness will be determined via the method 'multiton_id' if you're class has implimented that instance method or the object in question responds to it otherwise. so, in your case, you might use something like hash.to_a.sort.hash or something unique like that. eg class MyClass include Multiton attr :multiton_id def initialize h = {} @multiton_id = h.to_a.sort.hash super end end kind regards. -a -- if you find yourself slandering anybody, first imagine that your mouth is filled with excrement. it will break you of the habit quickly enough. - the dalai lama