【发布时间】:2011-11-05 17:15:26
【问题描述】:
在 Ruby 中重新定义一些常量(例如 FOO = 'bar')会生成警告 already initialized constant。
我正在尝试编写一种ReallyConstants 模块,该代码应该具有这种行为:
ReallyConstants.define_constant(:FOO, 'bar') #=> sets the constant ReallyConstants::FOO to 'bar'
ReallyConstants::FOO #=> 'bar'
ReallyConstants::FOO = 'foobar' #=> this should raise an Exception
也就是说,常量重定义应该会产生异常。
这可能吗?
【问题讨论】:
标签: ruby constants redefinition