From: Mauricio Fernandez Date: 2006-05-06T19:50:33+09:00 Subject: Re: Sharp knives and glue On Sat, May 06, 2006 at 06:20:54PM +0900, Alex Young wrote: > $ ruby -r freeze-core -e 'class String; def len; "foo"; end; end' > -e:1: can't modify frozen class (TypeError) ... > >>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.) ======================= > 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? Several implementations have been proposed on ruby-talk before; they failed in cases like $ cat bad.rb ::String.class_eval do # forces top-level, defies our efforts to wrap it def size; 0 end end $ cat naive.rb a = "foo" p a.size load("bad.rb", true) p a.size p $" $ ruby naive.rb 3 ./bad.rb:3: warning: method redefined; discarding old size 0 [] See http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/27417 for another proposal. -- Mauricio Fernandez - http://eigenclass.org - singular Ruby