From: Jeremy Hinegardner Date: 2008-05-23T03:22:40+09:00 Subject: Re: Prevent ruby constant variables from changing? On Thu, May 22, 2008 at 04:49:32PM +0900, Pe??a, Botp wrote: > From: George Wang [mailto:stdcells@yahoo.com] > > i too had this problem, and the closest i can get is to wrap the constants in > a module and then freeze the module. Interesting new knowledge for me when I test this out. I didn't know that what is returned from the end of a class ... end and module .. end block is NilClass. % cat x.rb module C X = 42 end.freeze puts "C::X => #{C::X}" C::X = 99 puts "C::X => #{C::X}" C.freeze C::X = 42 puts "C::X => #{C::X}" % ruby x.rb C::X => 42 x.rb:6: warning: already initialized constant X C::X => 99 x.rb:10: can't modify frozen module (TypeError) Hmm... lets look at what is returned by the end of a module and a class % cat c.rb c = class C; end puts c.inspect m = module M; end puts m.inspect % ruby c.rb nil nil You learn something new every day. enjoy, -jeremy -- ======================================================================== Jeremy Hinegardner jeremy@hinegardner.org