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

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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -