Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a Rails nested module as follow:

lib
 - Parent
   - Child1.rb
   - Child2.rb

In Child1.rb I define:

module Parent
  module Child1
  end
end 

Child2 module is defined similarly.

In my model, I call:

model MyModel
   include Parent::Child1
   include Parent::Child2
end

I have a few constants to be shared between Child1 and Child2. How should I go about implementing it?

share|improve this question

1 Answer

Create a file called parent.rb in lib to define the parent module and put the constants in there

module Parent
  CONSTANT1 = "1"
  CONSTANT2 = "2"
end

both constants will now be available in your child modules

Structure will look like

lib
 - Parent
   - child1.rb
   - child2.rb
 - parent.rb
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.