From: Dave Bass Date: 2008-05-24T01:29:24+09:00 Subject: Re: Prevent ruby constant variables from changing? Pe単a, Botp wrote: > i too had this problem, and the closest i can get is to wrap the > constants in a module and then freeze the module. I was inspired by Perl's use of subroutines as wrappers for constants to come up with the following technique. It doesn't involve modules or freezing: irb(main):001:0> def self.Const irb(main):002:1> 1 irb(main):003:1> end => nil irb(main):004:0> self.Const => 1 irb(main):005:0> self.Const = 2 NoMethodError: undefined method `Const=' for main:Object from (irb):5 irb(main):006:0> self.Const => 1 Anyone see problems? It at least avoids accidental modification of a constant, and it's simple. -- Posted via http://www.ruby-forum.com/.