From: Harry Ohlsen Date: 2001-11-30T01:14:41+09:00 Subject: [ruby-talk:26921] Re: overload possible? In article , "Robert Feldt" wrote: >> 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). Well, you don't need to rewrite it. All you need to do is add the code for the new set of argument types. I guess this would be an issue if you didn't have the original code, though. >> > 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? I think I see what you're getting at now. With the mechanism I suggested, you'd have a problem, because you can't easily just go and edit the definition of Fixnum#+, so you'd have to do the alias ... as you say. That certainly means it's not available in all cases. However, I didn't think the person who asked the original question meant that kind of thing. I thought they were talking about code they were writing for themselves. It would definitely be nice to have something that worked in all cases, which I think yours would. However, I'd personally give up that generality for what I think is a more straightforward style of defining the methods. Obviously, that's only for my personal definition of "more straightforward" :-). > Yes, but when you want to add and overload dynamically (at different > time and from different files etc), how do you do it? Yep. Agreed. This is what I hadn't originally thought about, and as I say, hadn't thought it was required by the original poster. I agree, not having that level of dynamic control does mean it doesn't fit in well with the ruby way of doing things !! > 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. True. > Well, maybe we should drop this; I guess this is not important enough to > warrant too much discussion... ;-) Agreed. I'll shut up now :-) !!