From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-07-02T01:50:14+09:00 Subject: Re: Concatenating Hash's On Wed, 25 Jun 2003 18:10:05 +0200, Robert Klemme wrote: > > "Simon Strandgaard" <0bz63fz3m1qt3001@sneakemail.com> schrieb im > Newsbeitrag news:pan.2003.06.25.08.56.32.933291@sneakemail.com... >> On Wed, 25 Jun 2003 10:45:02 +0200, Robert Klemme wrote: >> > >> > def hash_join(h1,h2); h1.dup.update(h2); end >> > >> > you could also do >> > >> > class Hash; def +(o); dup.update(o); end; end >> > >> > h1={1,2,3,4} >> > h2={"a","b"} >> > h1 + h2 # => {"a"=>"b", 1=>2, 3=>4} >> >> >> If your hash-tables has differents sizes, I suppose that it will be >> fastest to merge the smallest into the biggest. > > You mean > > class Hash; def +(o); if size >= o.size then dup.update(o); else o+self; > end; end; end > > ? Hmm.. In Ruby-1.8.0 there is also: Hash#merge and Hash#merge! How is Hash#update different from Hash#merge! are one just an aliases ? -- Simon Strandgaard