From: benny Date: 2004-01-28T02:04:55+09:00 Subject: Re: newbee question about "missing" hash methods +, += and << > First of all, no class has a method "+=". Instead this is a syntactic > shortcut that transforms "a += b" into "a = a + b" - whatever 'a' and 'b' > are. ok > > > I would find it intuitive if I could do something like this > > > > testhash = Hash.new > > testhash << {"some key" => "some value"} > > There is "update": yes, I know, but I thought about syntactic consistency perhaps I have an interation about differenz objects, some of them are arrays, some are hashs (and I don't want to check it all the time) > > I guess it's that Hash#update is peculiar because it depends on which hash > is updated by the other, which is important if both Hashes share some > keys. but its quite clear: the right hash replaces the entry in the left hash with the same key, just like update. why inventing a new method name for basically same thing? > Apart from that Hash#+ might be a bit inefficient in situations > where you want to update a Hash via +=. > thats the samething with teststring = "hello" teststring += " boys and girls" vs teststring << "boys and girls" so why not having "<<" (without temporary object) and "+" or "+=" (with temporary object) instead of "update"? I'm not convinced yet.