lundi 24 août 2015

How does '::' at the beginning of the class affect scope (ruby/rails)?

I'm working in a large rails project where I have some files:

app/services/my_service/my_action/my_model_2.rb:

module <my_service>
  module <my_action>
    class <my_model_2>
      . . .
      if some_var = <my_model>::MY_CONST
      if some_Var = ::<my_model>::MY_CONST # <-- what is the difference here?

app/services/my_service/my_action/my_model.rb:

module <my_service>
  module <my_action>
    class <my_model>

app/services/my_service/my_model.rb:

module <my_service>
    class <my_model>

app/models/my_model.rb:

class <my_model> < ActiveRecord::Base
  . . . 
  MY_CONST = "my constant"

What is the difference in my_model_2.rb?

How would I scope correctly to access each of the models from my_model_2.rb?

Note that app/models class name is the same as app/services class name.

Aucun commentaire:

Enregistrer un commentaire