From: Trans Date: 2006-09-29T02:45:29+09:00 Subject: Re: Multi-Module Alternative to the Factory Pattern? ara.t.howard@noaa.gov wrote: > why not: > [snip] Only becuase there are a lot of arguments to pass. > btw. for these kinds of setups: modules with state (singletons) i've been > using prototypes lately: Right on. I do like the prototype stuff. Just don't have the time to invest init at them moment though. [snip cool example use of prototype] > i guess i'm failing to see what multi-module inclusion givs you that delegation > plus argument passing (into the delegate module not the other way around) > doesn't? The advantage is access to the internal state --no passing of attributes required. Esspecailly true when you have alot of attributes/arguments involved. Simple example: require 'facet/kernel/as' module DEB A, B, C = %w( D E B ) def pack_step_one() p A+a end def pack_step_two() p B+b end def pack_step_three() p C+c end end module RPM A, B, C = %w( R P M ) def pack_step_one() p A+a+b+c end def pack_step_two() p B+b+c+a end def pack_step_three() p C+c+a+b end end class Packager include DEB, RPM attr :a,:b,:c def initialize @a,@b,@c = %w{ 1 2 3 } end def pack type as(type).pack_step_one as(type).pack_step_two as(type).pack_step_three end end packager = Packager.new packager.pack DEB, 42 harp:~ > ruby a.rb "D123" "E231" "B312" 42 Note #as works like #superior from my last example but uses magic-dot notation to allow any method to be called. (It would be nice if it took a block but I'll have to work on that). T.