From: Ben Tilly Date: 2001-02-26T22:36:38+09:00 Subject: [ruby-talk:11589] Re: Array bugs? I hate following up to myself but... "Ben Tilly" wrote: > >"Christoph Rippel" wrote: [...] >Now the right way to do the caching strategy above >would be to make methods like <=> be able to take >1 or 2 arguments. The optional argument would be >the recursive cache, and the above check would be >inserted into all of them. Which would mean that >you would move the cache code into Enumerable and >then just call: > > @cache, is_seen = check_cache(@cache, self.id, other.id) > >in every comparison method. [...] The better way would be for Enumerable to add methods for get_cache, in_cache?, <=>, cmp, and for those who want an efficient ==, eq. The difference between == and eq, or <=> and cmp would be 1 argument or 2. The second argument is the cache. The <=> method would just add in an empty cache and call cmp. The cmp method would just call <=>. Classes which are complex data structures should provide cmp and mixin <=>. Simple classes should provide <=> and mixin cmp. Similarly eq would just throw ==. Inside of cmp in complex data structures you are expected to do your own: return true if in_cache?(cache, id, other.id) Thoughts? Feedback? Cheers, Ben _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com