From: "Brian Schröder" Date: 2005-08-26T21:17:26+09:00 Subject: Re: Circular dependecy on classes On 26/08/05, Anatol Pomozov wrote: > I have several classes that have circular dependencies on each other. > See following example. > > class Solder > @can_upgrade_to = [Knight] > #or use constant from Knight class > > def upgrade!(to) > raise "Unable to upgrade" unless @can_upgrade_to.contain(to) > end > end > > class Knight < Solder > end > > I cant use Knight constant (class name) before Solder and can't use > Solder before Knight. > > I am just come from Java lang and for Java circular class deps is not > a problem. > But ruby is a dynamic language and it creates classes just on script > executing. (right?) > > So my questions is: how to solve this problem? What is the best way to > deal with it. > > -- > anatol > > You could reopen the class. That works like predeclaration in other languages. class Soldier end class Knight < Soldier end class Soldier @can_upgrade_to = [Knight] ... end regards, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/