On 5/15/06, ara.t.howard / noaa.gov <ara.t.howard / noaa.gov> wrote:
> On Tue, 16 May 2006, Pat Maddox wrote:
>
> > 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.
> >
> > Pat
>
> a setup like this will give you that
>
>    harp:~ > cat foo_constants.rb
>    module FooConstants
>      FOO = 42
>    end
>
>    harp:~ > cat foo.rb
>    require 'foo_constants'
>    class Foo
>      include FooConstants
>    end
>
>    harp:~ > cat bar.rb
>    require 'foo_constants'
>    class Bar
>      include FooConstants
>      def self.set_foo(val)
>        define_method(:foo) { val }
>      end
>    end
>
>    harp:~ > ruby foobar.rb
>    42
>
>
> hard to understand __why__ you'd do that - but factoring module-wise will
> certainly lead to an elegant answer.

Thanks for the response Ara.

Do you mean it's hard to understand why I'd set things up the way I
have them?  Or do you mean that factoring the constants out is a non
obvious solution?

Anyway what really interests me is why I only have this problem when
I'm calling the class method that calls define_method inside it.  If
you look at it, instance methods and class methods all work fine.  If
it were purely a class loading issue, shouldn't it blow up in other
cases as well?

Pat