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
Post a Comment