From: Robert Feldt Date: 2001-11-30T00:02:18+09:00 Subject: [ruby-talk:26905] Re: overload possible? On Thu, 29 Nov 2001, Harry Ohlsen wrote: > > 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 mean rewrite the method we're overloading (in my solution the dispatching method). > > 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. > Yes, but the overload/dispatch tool should do it. > > 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. > Yes, but when you want to add and overload dynamically (at different time and from different files etc), how do you do it? Anyway you can have it "both" ways by doing it with a directive but allowing the final arg to be a block dispatch :overloaded_method, String, proc{|str| ...} or something like that. Well, maybe we should drop this; I guess this is not important enough to warrant too much discussion... ;-) Regards, Robert