From: Austin Ziegler Date: 2006-05-16T06:14:10+09:00 Subject: Re: Weird class-loading issue (or maybe a problem with define_method?) On 5/15/06, Pat Maddox wrote: > On 5/15/06, Austin Ziegler wrote: >> On 5/15/06, Pat Maddox wrote: >>> I'm working on an app and having a strange class loading problem. >>> I've extracted it to the most basic code possible. >> >> Change this: >>> # foo.rb >>> require "bar" >>> class Foo >>> FOO = "foo" >>> end >> >> to this: >> >> # foo.rb >> class Foo >> FOO = "foo" >> end >> require "bar" > I can't, because some of the methods in the Foo class call Bar methods. Do you mean: class Foo FOO = foo def initialize(mybar) @bar = mybar end def baz # ... stuff ... @bar.baz # ... stuff ... end end If that's the case, then you can do it. >> Better yet, get rid of your circular dependency. >> >> FooBar should be defined in a third file that requires foo.rb and >> bar.rb. > I'm not sure how that fixes anything. Foo has to create some Bar > objects, and Bar has to have access to some of the Foo constants. I > didn't talk about that in my initial post, but each class interacts > with each other. I think you're going to need to be a bit clearer about what you're *actually* trying to do, because this sounds like an incredibly bad design. Circular dependencies are bad. If you must absolutely have it, take advantage of Ruby's open classes. But try to avoid it. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca