From: Trans Date: 2007-03-17T02:51:57+09:00 Subject: Re: java guilt On Mar 16, 12:49 pm, Pit Capitain wrote: > Trans schrieb: > > > > > I wrote an experimental lib a while back that let you sub in your > > class for another within the scope of another module/or class. I think > > it's a pretty easy way to work with this concept. Far-sight better > > than the clock based approaches, IMO. The central idea is: > > > class InBlanket > > > # This would have a even nicer DSL. > > > String = Class.new(::String) do > > def to_s; "(" + super + ")" > > end > > > def tryme > > puts "three pigs" > > end > > > end > > > InBlanket.new.tryme #=> "(three pigs) > > > This could actually be made to work fairly easily *if* literals used > > the ::new methods. Unfortunately they don't. So one would have to do > > back and use String.new instead of "". I consider this a design flaw > > in Ruby current implementation, though I'm sure there are > > justifications for it (probably execution speed related). > > Tom, what would happen in your implementation if I pass a string from > the outside to tryme? And what would happen if I use a string created in > InBlanket outside of the class? Good point, Pit. The String defined outside would not be effected. Most data comes from the outside, so there's really no point to this unless the incoming data is recast into the extended version automatically (or manually?). T.