From: matz@... (Yukihiro Matsumoto) Date: 2003-01-02T13:23:29+09:00 Subject: Re: How to extend Hash Hi, In message "How to extend Hash" on 03/01/02, TOTO writes: |I am trying to extend the Hash class so that I can "Insert the content |of a Hash object to another Hash object". | |However, the internal code for Hash is written in c. Is it possible to |extend the class using ruby itself? How, since we don't know the |internal data structures of class Hash. It is possible, just like other Ruby-defined classes. But first you can check out "update" method for Hash class. matz. ------------------------------------------------------------ Hash#update hsh.update( anOtherHash ) -> hsh ------------------------------------------------------------------------ Adds the contents of anOtherHash to hsh, overwriting entries with duplicate keys with those from anOtherHash. h1 = { "a" => 100, "b" => 200 } h2 = { "b" => 254, "c" => 300 } h1.update(h2) #=> {"a"=>100, "b"=>254, "c"=>300}