ruby on rails - When is executed the code defined in the class section of the model -


if put in model:

class sample < applicationrecord   enum level: [:one, :two, :three].map{|e| [e,e]}.to_h 

this section

[:one, :two, :three].map{|e| [e,e]}.to_h 

will executed once? when model first loaded? or executed multiple times?

once, when model loaded. in ruby, class definition code, enum in example method call, , [:one, :two, :three].map{|e| [e,e]}.to_h argument.

the end result of calling enum several other methods defined on class, allowing things sample.two? per docs.

have read of source code on github if want know how happens.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -