From: Alan Chen Date: 2002-07-08T03:46:21+09:00 Subject: Re: passing to objects at the bottom On Sun, Jul 07, 2002 at 04:33:27PM +0900, Tom Sawyer wrote: > hey i found the answer! i got a clue from david. thanks david. > > the trick is to use a class variable in a module, along with a class > method for setting it, and then include it in the "bottom" class. > > module Prefix > @@prefix > def set_prefix(x) > @@prefix = x > end > end > > class Bottom > include Prefix > def initialize > puts @@prefix > end > end > > class Top > def initialize > Prefix.set_prefix('whatever') > end > end > > and bingo! > > ~transami That design looks a little ugly to me. For one, if you can't have more than one tree with different prefixes with that design. You're esentially using an obfuscated global variable. How about just passing prefix to the bottom element at instantiation? class Bottom def initialize(name) end end class Top def initialize @prefix = 'pro' @bottom_array = [] end def add_bottom(name) @bottom_array << Bottom.new( "#{@prefix}_name" ) end end -- Alan Chen Digikata LLC http://digikata.com