From: Robert Klemme Date: 2012-08-27T18:25:31+09:00 Subject: Re: A Ruby class is never closed On Mon, Aug 27, 2012 at 10:58 AM, Ryan Davis wrote: > > On Aug 27, 2012, at 01:47 , Robert Klemme wrote: > >> On Sat, Aug 25, 2012 at 11:36 PM, Marc Heiler wrote: >>> I think he basically wants to have a class that can never ever again be >>> changed. >>> >>> As far as I know, this is not possible in ruby. >> >> In what ways can you still change a frozen class? > > class X; freeze; end > X = X.dup The constant reassignment will prompt a warning. > class X; def y; end; end # works fine You are not actually modifying the original class X. Instead you create a copy and modify that. > The people looking for these assurances have to be educated that it just isn't something that is worthwhile trying here. Well, at least particular measures help others recognize that it is a bad idea what they are trying (i.e. doing the dup reassign trick you present above can be done but will prompt a warning). Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/