From: "T. Onoma" Date: 2003-12-15T01:11:22+09:00 Subject: Re: inplace assignment On Sunday 14 December 2003 03:59 pm, David A. Black wrote: > I'm not sure what you mean by "duck similar" (the notion of duck > typing doesn't scale well to "duck "), but assuming you > mean a class that defines methods with the same names and arities as > another class, the best thing would probably be to do: See, you knew exactly what I was talking about, and I only used two words! Seems to scale fairly well ;-) > module A; # bunch of methods; end > module B; # same-named methods as A; end > > class C; include A; end > class C; include B; end # when you want the new ones > > or > > class C; include A; end > c = C.new > obj.extend(B) > > > Okay, so it's a bit crazy. But I actually came across a use for this. > > Luckly my situation is specialized --I am replacing the class with a > > subclass of it, so I discovered that I could just do this: > > > > class MyClass < MyClass > > Yikes. I *think* that resorting to that is a reasonably good > indication that you might want to look for a new program design :-) Well, I'm working on some method wrapping implementaions, seeing how far I can coerce Ruby into doing some of the things Peter and I are talking about. So Yikes aren't too out of the ordinary. But, I actually did find a better way to do it this morning, by redefining MyClass#new to return a subclass of itself instead. Hmm..I forget, what kind of design pattern is that? Thanks, T.