Comments on: already initialized constant in fixtures https://fromdelhi.com/2006/08/21/already-initialized-constant-in-fixtures/ Thu, 08 Mar 2007 16:56:29 +0000 hourly 1 https://wordpress.org/?v=5.3.21 By: Anthony Eden https://fromdelhi.com/2006/08/21/already-initialized-constant-in-fixtures/#comment-164 Thu, 08 Mar 2007 16:56:29 +0000 http://www.fromdelhi.com/2006/08/21/already-initialized-constant-in-fixtures/#comment-164 How about:

SALT ||= “nacl”

Works great in irb.

]]>
By: Sheldon Hearn https://fromdelhi.com/2006/08/21/already-initialized-constant-in-fixtures/#comment-163 Mon, 21 Aug 2006 20:05:48 +0000 http://www.fromdelhi.com/2006/08/21/already-initialized-constant-in-fixtures/#comment-163 This is a common idiom from other areas of your application too, like controllers and models:

SALT = “nacl”.freeze unless const_defined? “SALT”

Note the freeze. The constantness of an object just prevents replacement of that object with another. Freezing the object ensures its attributes can’t be changed.

]]>