From: Pat Maddox Date: 2006-05-16T17:27:12+09:00 Subject: Re: Weird class-loading issue (or maybe a problem with define_method?) On 5/15/06, Austin Ziegler wrote: > 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. I went through Ch1 of Refactoring, using rspec to write the tests. After I was done with all the refactorings, I wanted to be able to specify a price code for each Price class by calling a class method, rather than defining one. I've got all the source code at http://svn.flpr.org/public/refactoringbdd It's very small, so it wouldn't take more than a few minutes to look at. Here's the original code for one class, with extraneous methods ripped out: class ChildrensPrice < Price def get_price_code Movie::CHILDRENS end end Here's what I'd like to do: class Price def self.price(val) define_method(:get_price_code) { val } end end class ChildrensPrice < Price price Movie::CHILDRENS end As you can see, instead of defining get_price_code, I just call Class.price and it defines the method for me. Currently the test suite runs fine. If you open specs/customer_spec.rb and delete the require "price" line though, it gives errors. Pat