From: Trans Date: 2007-10-16T05:33:35+09:00 Subject: Re: RubyTraits 0.1 On Oct 15, 9:49 am, Daniel Berger wrote: > On Oct 15, 9:38 am, Yukihiro Matsumoto wrote: > > > > > Hi, > > > In message "Re: RubyTraits 0.1" > > on Tue, 16 Oct 2007 00:23:43 +0900, Trans writes: > > > |I see. So you don't really like the fact that modules fit into the > > |inheritance chain? That's interesting. > > > Actually they both have their own good. I like them both. I dislike > > to have them both in a language. Traits injection is clear and less > > error prone (there's no possibility of conflicts), but sometimes > > method overriding is _very_ useful, where aliasing is very poor way to > > create method combination. > > > If someone come to the idea to allow modules to have merits from both > > mixins and traits at once (without demerit), I'd love to hear. > > I solved this "problem" over two years ago with fine grained mixins. > Please seehttp://rubyforge.org/docman/view.php/735/309/README.html > and look at the synopsis. Ideas (and code) in that library also came > from Ara Howard and Mauricio Fernandez. > > I don't want up front object composition. To me that's like static > typing, except for object composition. At worst, a warning should be > issued if a double inclusion occurs. This is what the 'use' library > does in verbose mode. Kind of like #integrate. # Using integrate is just like using include except the # module included is a reconstruction of the one given # altered by the commands given in the block. # # Convenient commands available are: #rename, #redef, # #remove, #nodef and #wrap. But any module method # can be used. # # module W # def q ; "q" ; end # def y ; "y" ; end # end # # class X # integrate W do # nodef :y # end # end # # x = X.new # x.q #=> "q" # x.y #=> NoMethodError # # This is like #revisal, but #revisal only # returns the reconstructred module. It does not # include it. The significant difference between this and your #use method is that #use can more easily add a small select group of methods from a module --I think that's that gist of your lib. However, if you find yourself "cherry picking" methods from a module like that, it's time to rethink the design. Plus, implementation of that is terribly inefficient (having to remove all other methods). At any rate, Traits are much prettier: class X include W - :y end T.