开发者

What (of bad) can happen if I state a constant value using '||='?

开发者 https://www.devze.com 2023-04-01 19:06 出处:网络
I am using Ruby on Rails v3.0.9 and I would like to know what (of bad) can happen if I state a constant value as this:

I am using Ruby on Rails v3.0.9 and I would like to know what (of bad) can happen if I state a constant value as this:

MAX_LENGTH ||= 30

BTW: I am developing an "acts_as_something" plugin (in my application more than开发者_运维问答 one class "acts_as_something") and I must state constant values like above in order to not show\generate "warning messages" in the /.../log/apache2/error.log (production mode) as the following:

warning: already initialized constant MAX_LENGTH


Warnings in general are never good. You might want to switch it to this:

unless (const_defined?(:MAX_LENGTH))
  MAX_LENGTH = 30
end
0

精彩评论

暂无评论...
验证码 换一张
取 消