From: Harry Ohlsen Date: 2001-11-29T23:14:22+09:00 Subject: [ruby-talk:26897] Re: overload possible? In article , "Robert Feldt" wrote: > Hi, > > Isn't a drawback with all the solutions based on dispatching to a block > that you need to rewrite the overloaded routine each time? Is that a > realistic assumption? I'm not sure what you mean by rewriting it each time. Surely, if you want specific code for a specific set of arguments, you're going to have to write that code. Maybe I'm missed what you were getting at. > I'm thinking if I want to overload Fixnum#+ because it should have a > special behavior when argument is my new class then I'd have to revert > to an alias-redefine-and-call scheme, right? But, you'd have to do that anyway. Again, maybe I'm missing your point. > I know my kludgy solution used an ugly "global" db but isn't that the > way to go if you want something like multi-methods dispatch? The only reason I suggested my original solution was more "obvious" was that it kept the set of arguments and the code together, rather than defining a bunch of separate routines to handle specific sets of arguments and then having separate lines that made the connection between those sets of arguments and the corresponding routines. I'm still of that opinion, but after the smarter people did some cleanup to make it all work nicely, it ended up not being quite so simple. However, the sets of arguments and the code are still together, which I think is nicer ... again, IMHO. > Still don't know if its something one would use but at least it would > let us experiment with multi-method dispatch to see if it would add > something to Ruby. I agree that it's not something one wants to do very often. The only reason I played with it originally was because someone pointed to multimethods, as provided by a perl module, as one of the things they thought was pretty cool about perl and I figured it should be possible to do something just as easily in ruby. I've never used it in any of my real code.