From: Dave Burt Date: 2006-04-27T20:30:38+09:00 Subject: Re: object available in one class but not another? Greg Coit wrote: > Playing around more with rrobots. > ... > Here's my code: > > http://rafb.net/paste/results/RtkFqy50.html > > Thanks for any and all help. Hi Greg, I'm going to ignore your question in hope that this advice is as useful as an answer would be. Don't include Robot in Radar or Gun. That type of relationship is "a Gun is a kind of Robot", which is not what you want. GoofeyDuck is your Robot. (Your problem is probably related to the fact that, for example, radar_heading inside a Radar object refers to that Radar's radar, whereas the parent GoofeyDuck has a separate radar. You have 4 robots, 3 inside the other 1!) Here's an alternative skeleton, with only 1 robot per robot: class GoofeyDuck include Robot def initialize @radar = Radar.new(self) @gun = Gun.new(self) @tank = Tank.new(self) end # This defines a class named GoofeyDuck::Radar. # You can refer to it as Gun inside GoofeyDuck's definition. class Radar def initialize(robot) @robot = robot end def target? puts @robot.radar_heading @robot.radar_heading + (@scan / 2) end #... end class Tank def initialize(robot) @robot = robot end #... end class Gun def initialize(robot) @robot = robot end #... end end Cheers, Dave