From: Robert Klemme Date: 2005-12-31T20:03:24+09:00 Subject: Re: get mixin's name Payton Swick wrote: > The goal was basically this for a GUI (the answer is probably that > there's a better way): > > module Layout > # ... layout stuff > def layout_name > 'none' > end > end > > module CoolLayout > include Layout > # ... override some layout stuff. > def layout_name > 'CoolLayout' # Not DRY > end > end > > class Window > def layout=(l) > extend l > end > end IMHO this is a bad idea because you cannot change layout that way multiple times. Once you extended an instance by a module this module stays in place even if you extend with a different module. Also, a Window *has* a layout - so composition is far more appropriate here than inheritance. And if you do that and model layouts as independent class hierarchy you can simply use the layout instance's class or it's name for the layout name. > a = Window.new > a.layout = CoolLayout > puts "This window has the layout #{a.layout_name}" I'd prefer to let the layout answer the question after its name which also nicely fits with the composition approach - and it helps keep the interface of Window focused: puts "This window has the layout #{a.layout.name}" Kind regards robert