From: Liquid Date: 2006-05-06T19:49:32+09:00 Subject: Re: Sharp knives and glue ------=_Part_75032_24581598.1146912569477 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Would this still allow extensions to an instance? This should still be allowed yes? @obj.extend(something) On 5/6/06, Alex Young wrote: > > Ryan Leavengood wrote: > > Cool, this sounds like a plan David. This was exactly what I wanted my > > email to achieve. While we Ruby programmer's love the power and > > flexibility of re-opening classes, there are probably times when we > > all want to lock things down. Having the *option* of doing this > > shouldn't hurt anything, in my opinion. > > > > FYI, I'm not sure if what you propose is possible in pure Ruby (at > > least easily), so if you can hack C you might have to look into making > > a C extension or a patch to the interpreter. Hopefully it won't be so > > bad though. > > $ cat freeze-core.rb > @classes =3D {} > def do_freeze(klass) > klass.freeze > @classes[klass] =3D true > end > ObjectSpace.each_object do |o| > do_freeze(o) if o.is_a?(Class) and !@classes.has_key?(o) > end > > $ ruby -r freeze-core -e 'puts "foo"' > foo > $ ruby -r rubygems -r freeze-core -e 'puts "foo"' > foo > $ ruby -r freeze-core -e 'class String; def len; "foo"; end; end' > -e:1: can't modify frozen class (TypeError) > > Something like that? > > It also struck me that the require mechanism could be hijacked to > enforce per-file namespacing to give something like Python's system, > which seems to work fairly well. A require_ns() that wraps a module > named after the filename around the code it includes... Would that help? > > -- > Alex > > > > > Regards, > > Ryan > > > > On 5/5/06, David Pollak wrote: > > > >> Ryan, > >> > >> So... "Put your code where your mouth is?"... and given that my mouth > is > >> big, my code should be good (my comments about me, and not ascribed to > >> you)... :-) > >> > >> I think you're absolutely right! > >> > >> I'll work on some 'lock-down' code that will allow classes to lock > >> themselves down from external modification (not Foo.freeze, but > something > >> more granular.) > >> > >> I'll toss it out to the group and see what people have to say. > >> > >> Thanks, > >> > >> David > > > > > > > ------=_Part_75032_24581598.1146912569477--