在 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
也就是说,常量重定义应该产生异常。
那可能吗?