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
つまり、一定の再定義によって例外が生成されるはずです。
それは可能ですか?