From: Josh Rendek Date: 2012-08-28T13:18:50+09:00 Subject: Re: A Ruby class is never closed A really simple way to ensure a class doesn't get modified: class Foo def Foo.method_added(name) raise "This class is closed for modification" end end class Foo def testing end end On 8/27/12 5:18 PM, Ryan Davis wrote: > On Aug 27, 2012, at 14:03 , Robert Klemme wrote: > >> Well, you may find the point subtle but the class you assign to X the >> second time is not the same as the one which was assigned the first >> time. The important bit here is that they do not share identity even >> though they can be accessed via the same constant (but at different >> times). This has serious implications especially if there are >> instances around of class #1: If you ask them for their class and try >> to modify it, the program will fail (unless there are some >> modifications possible which I have overlooked - see above). > gem install change_class > > o.class = SomeOtherClass > > done > >