0
我想初始化一個常量,如果它不存在,如果已經存在,然後使用它。我嘗試了下面的警告。如何處理初始化常量?
User = User || Struct.new(:name) #NameError: uninitialized constant User
User = Struct.new(:name) || User #works (1st time)
但這句話會遇到多次,這種情況發生時,我得到
User = Struct.new(:name) || User
#warning: already initialized constant User
#warning: previous definition of User was here
如何處理這種情況?
啊哈,我覺得'a || = b'等於'a = a || b' – Bala
@Bala不,它不是..我明白, –