From: Robert Klemme Date: 2004-01-29T00:15:10+09:00 Subject: Re: newbee question about "missing" hash methods +, += and << "benny" schrieb im Newsbeitrag news:20040128123045.778465a9@bava.ho... > > > > > [dolio 04:59:10 ~]$ cat prac.rb > > #!/usr/bin/ruby > > > > a = { 1 => 2 } > > b = { a => 3 } > > > > p b > > > > b.delete a > > > > p b > > > > [dolio 04:59:14 ~]$ ./prac.rb > > {{1=>2}=>3} > > {} > > > > In your test, the { "foo" => "bar" } stored in the first hash wasn't the > > same as the > > one you tried to delete later (different objects/ids, same structure). > > Hashes for > > objects only have to be the same if #eql? returns true between them, and > > that's > > not necessarily the case for two structrurally identical hashes (it's > > true only if they're > > the same object). > > > > As I recall, in Python you can only use immutable things as keys to hashes. > > However, in Java, for example, you can use any Object, whether it's a > > String or > > a Hashtable, so Ruby isn't alone. C++ typedef std::map< std::map, std::string> Foo; > ok, thank you for your explanation: I learn a lot from that! > > but when do we need such a thing? isn't it the contrast of the sense of an key and performance > hungry? The interesting thing about OO is that you provide components (classes) that will be used in ways that you might not be able to think of. This is even more true for general purpose classes such as Hash, Array and the like. Maybe someone implements a class by inheriting Hash and adding some methods and wants to use this as Hash key. Who knows? robert