How to redefine a Ruby constant without warning?

后端 未结 4 1560
眼角桃花
眼角桃花 2020-12-23 15:57

I\'m running some Ruby code which evals a Ruby file every time its date changes. In the file, I have constant definitions, like

Tau = 2 * Pi
<
4条回答
  •  一个人的身影
    2020-12-23 16:36

    Unless the values of the constants are pretty weird (i.e. you have constants set to nil or false), the best choice would be to use the conditional assignment operator: Tau ||= 2*Pi

    This will set Tau to 2π if it is nil, false or undefined, and leave it alone otherwise.

提交回复
热议问题