Check if a constant is already defined

后端 未结 3 1901
故里飘歌
故里飘歌 2020-12-09 00:45

This is a simple one, I hope. How do I check, in the following example, if a constant is already defined?

#this works
var = var||1
puts var
var = var||2
put         


        
3条回答
  •  天命终不由人
    2020-12-09 01:16

    const_defined? API

    pry> User.const_defined?("PER_PAGE")
    => true
    pry> User.const_defined?("PER_PAGE123")
    => false
    

提交回复
热议问题