-1

In a rails project I have the class:

class Police::Office 
end

Now I create an Interactor in the same namespace:

class Police::Office::ConstructInteractor 
end 

1. Is this allowed or can it provoke name clashes?

2. What is Police::Office::ConstructInteractor?

Is it a class in a module like:

module Police::Office
  class ConstructInteractor 
  end
end 

Or a class in a class?

class Police::Office
  class ConstructInteractor 
  end
end

Thank you

John Smith
  • 6,105
  • 16
  • 58
  • 109

1 Answers1

2

1. Is this allowed

Of course it is allowed. Classes are allowed to contain constants. (BTW: it would have taken you only a couple of seconds to try it out yourself.)

or can it provoke name clashes?

I have no idea what that means, but again, you can easily test it out yourself by just copy&pasting the code you posted and run it.

2. What is Police::Office::ConstructInteractor?

Is it a class in a module like:

module Police::Office
  class ConstructInteractor 
  end
end 

Of course not. You defined Police::Office to be a class earlier, so it obviously is a class.

Or a class in a class?

class Police::Office
  class ConstructInteractor 
  end
end

Yes. But note that this is not a "class in a class". This is a constant in a class. In Ruby, classes don't nest like they do in Beta, gBeta, Newspeak, or Scala (not even like in Java). There is no relationship whatsoever between the class referenced by the constant Police::Office::ConstructInteractor and the class referenced by the constant Police::Office.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653