From: Paul Brannan Date: 2003-09-10T05:40:12+09:00 Subject: Re: ANN: MetaTags 1.0 On Tue, Sep 09, 2003 at 12:59:49PM +0900, Dave Thomas wrote: > class Caml > def Caml.from_string(str) > # .. check string format .. > self.new(str) # or something similar > end > end > > def Caml(str) > Caml.from_string(str) > end A side-effect of this is that once all classes have a from_string singleton method and a to_s instance method, I can now write: class Object def lexical_to(klass) return klass.from_string(to_s()) end end which is similar to boost::lexical_cast in C++: template Target lexical_cast(Source arg) { std::stringstream interpreter; Target result; interpreter << arg; interpreter >> result; return result; } (the actual implementation has a bit more than this with error checking and such). Paul