From: Jack Christensen Date: 2005-12-29T14:01:58+09:00 Subject: Re: Locking classes? Max Eskin wrote: >Hi, >I am just starting to use Ruby. I'm wondering, once a class has been >declared, is there any way to lock it to prevent further methods from >being defined? In other words is there a way to make Ruby act like a >static language for some classes? > > > freeze the class. Example: irb(main):001:0> class A irb(main):002:1> def f irb(main):003:2> 42 irb(main):004:2> end irb(main):005:1> end => nil irb(main):006:0> A.freeze => A irb(main):007:0> class A irb(main):008:1> def g irb(main):009:2> 43 irb(main):010:2> end irb(main):011:1> end TypeError: can't modify frozen class from (irb):8 Jack