Constant definition in Ruby/RailsHow can I “pretty” format my JSON output in Ruby on Rails?How to get a random number in RubyA concise explanation of nil v. empty v. blank in Ruby on RailsUnderstanding the Rails Authenticity TokenHow to write a switch statement in RubyCheck if a value exists in an array in RubyHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?Ruby on Rails Server optionsWhat is attr_accessor in Ruby?

Prove that NP is closed under karp reduction?

Theorem, big Paralist and Amsart

Python: next in for loop

What typically incentivizes a professor to change jobs to a lower ranking university?

What is the offset in a seaplane's hull?

The use of multiple foreign keys on same column in SQL Server

Why are electrically insulating heatsinks so rare? Is it just cost?

Theorems that impeded progress

Do VLANs within a subnet need to have their own subnet for router on a stick?

What does "Puller Prush Person" mean?

How can I make my BBEG immortal short of making them a Lich or Vampire?

How can bays and straits be determined in a procedurally generated map?

Have astronauts in space suits ever taken selfies? If so, how?

How to test if a transaction is standard without spending real money?

Writing rule stating superpower from different root cause is bad writing

Risk of getting Chronic Wasting Disease (CWD) in the United States?

Which models of the Boeing 737 are still in production?

Minkowski space

How to say job offer in Mandarin/Cantonese?

Mathematical cryptic clues

"You are your self first supporter", a more proper way to say it

Why not use SQL instead of GraphQL?

Today is the Center

Why can't I see bouncing of a switch on an oscilloscope?



Constant definition in Ruby/Rails


How can I “pretty” format my JSON output in Ruby on Rails?How to get a random number in RubyA concise explanation of nil v. empty v. blank in Ruby on RailsUnderstanding the Rails Authenticity TokenHow to write a switch statement in RubyCheck if a value exists in an array in RubyHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?Ruby on Rails Server optionsWhat is attr_accessor in Ruby?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have initializers config in my rails application under config/initializers/my_config.rb.



What is the difference between:



A:



module MyModule
Config = "path/to/config.yml"
end


and:



B:



MyModule::Config = "path/to/config.yml"


Let's suppose we do some requests, change its implementation, and hit the application again. If I defined my constant the B way, I get an error:



uninitialized constant MyModule::Config


It will be resolved only when I restart my rails server. But when I do the A way, it still recognized the constant when I updated my code.



What is the importance of using the A syntax in this case?










share|improve this question






























    1















    I have initializers config in my rails application under config/initializers/my_config.rb.



    What is the difference between:



    A:



    module MyModule
    Config = "path/to/config.yml"
    end


    and:



    B:



    MyModule::Config = "path/to/config.yml"


    Let's suppose we do some requests, change its implementation, and hit the application again. If I defined my constant the B way, I get an error:



    uninitialized constant MyModule::Config


    It will be resolved only when I restart my rails server. But when I do the A way, it still recognized the constant when I updated my code.



    What is the importance of using the A syntax in this case?










    share|improve this question


























      1












      1








      1








      I have initializers config in my rails application under config/initializers/my_config.rb.



      What is the difference between:



      A:



      module MyModule
      Config = "path/to/config.yml"
      end


      and:



      B:



      MyModule::Config = "path/to/config.yml"


      Let's suppose we do some requests, change its implementation, and hit the application again. If I defined my constant the B way, I get an error:



      uninitialized constant MyModule::Config


      It will be resolved only when I restart my rails server. But when I do the A way, it still recognized the constant when I updated my code.



      What is the importance of using the A syntax in this case?










      share|improve this question
















      I have initializers config in my rails application under config/initializers/my_config.rb.



      What is the difference between:



      A:



      module MyModule
      Config = "path/to/config.yml"
      end


      and:



      B:



      MyModule::Config = "path/to/config.yml"


      Let's suppose we do some requests, change its implementation, and hit the application again. If I defined my constant the B way, I get an error:



      uninitialized constant MyModule::Config


      It will be resolved only when I restart my rails server. But when I do the A way, it still recognized the constant when I updated my code.



      What is the importance of using the A syntax in this case?







      ruby-on-rails ruby






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 10:50









      chumakoff

      4,13911233




      4,13911233










      asked Mar 21 at 23:51









      Kris MPKris MP

      56811024




      56811024






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Part of this seems to have to do with rails hot code reloading, which has a bunch of caveats. If you aren't using hot code reloading, A and B are more equivalent, as long as MyModule has been defined first.



          However, when code is reloaded, (particularly the file that defines MyModule), it might end up overwriting the existing module, and not running the B line.



          The main difference though, is that A doesn't rely on how the order of other code in the project is loaded/run, but B must be run after certain code.






          share|improve this answer






























            0














            The differences is that code A raises a syntax error, while code B is grammatical. Code B will raise a name error for MyModule unless it is previously defined, though.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290889%2fconstant-definition-in-ruby-rails%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Part of this seems to have to do with rails hot code reloading, which has a bunch of caveats. If you aren't using hot code reloading, A and B are more equivalent, as long as MyModule has been defined first.



              However, when code is reloaded, (particularly the file that defines MyModule), it might end up overwriting the existing module, and not running the B line.



              The main difference though, is that A doesn't rely on how the order of other code in the project is loaded/run, but B must be run after certain code.






              share|improve this answer



























                1














                Part of this seems to have to do with rails hot code reloading, which has a bunch of caveats. If you aren't using hot code reloading, A and B are more equivalent, as long as MyModule has been defined first.



                However, when code is reloaded, (particularly the file that defines MyModule), it might end up overwriting the existing module, and not running the B line.



                The main difference though, is that A doesn't rely on how the order of other code in the project is loaded/run, but B must be run after certain code.






                share|improve this answer

























                  1












                  1








                  1







                  Part of this seems to have to do with rails hot code reloading, which has a bunch of caveats. If you aren't using hot code reloading, A and B are more equivalent, as long as MyModule has been defined first.



                  However, when code is reloaded, (particularly the file that defines MyModule), it might end up overwriting the existing module, and not running the B line.



                  The main difference though, is that A doesn't rely on how the order of other code in the project is loaded/run, but B must be run after certain code.






                  share|improve this answer













                  Part of this seems to have to do with rails hot code reloading, which has a bunch of caveats. If you aren't using hot code reloading, A and B are more equivalent, as long as MyModule has been defined first.



                  However, when code is reloaded, (particularly the file that defines MyModule), it might end up overwriting the existing module, and not running the B line.



                  The main difference though, is that A doesn't rely on how the order of other code in the project is loaded/run, but B must be run after certain code.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 22 at 0:04









                  Garrett MotznerGarrett Motzner

                  823315




                  823315























                      0














                      The differences is that code A raises a syntax error, while code B is grammatical. Code B will raise a name error for MyModule unless it is previously defined, though.






                      share|improve this answer



























                        0














                        The differences is that code A raises a syntax error, while code B is grammatical. Code B will raise a name error for MyModule unless it is previously defined, though.






                        share|improve this answer

























                          0












                          0








                          0







                          The differences is that code A raises a syntax error, while code B is grammatical. Code B will raise a name error for MyModule unless it is previously defined, though.






                          share|improve this answer













                          The differences is that code A raises a syntax error, while code B is grammatical. Code B will raise a name error for MyModule unless it is previously defined, though.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 22 at 7:33









                          sawasawa

                          1




                          1



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290889%2fconstant-definition-in-ruby-rails%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript