From: Tom Sawyer Date: 2002-07-07T16:33:27+09:00 Subject: Re: passing to objects at the bottom 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 On Sat, 2002-07-06 at 17:11, Tom Sawyer wrote: > i have a chain of objects such that one object contains another which > contains another, and so on, down the line. the top object recieves a > parameter which only the bottom most object in the chain is going to > need. but how do i get it down there with out passing it through all the > rest? and not using a global variable? for example: > > class Top > def initialize(a) > Middle.new(a) > end > end > > class Middle > def initialize(a) > Bottom.new(a) > end > end > > class Bottom > def initialize(a) > puts a > end > end > > A.new("Thanks! I need that.") > > how do i get a to Bottom without going through Middle, since Middle > dosen't really need a. of course in my real program, i have about 4 > middles. does anyone have any better solutions to this problem? > > -- > ~transami > > "They that can give up essential liberty to obtain a little > temporary safety deserve neither liberty nor safety." > -- Benjamin Franklin > > -- ~transami "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -- Benjamin Franklin