From: Eric Mahurin Date: 2005-09-14T06:50:06+09:00 Subject: Re: yet another simple command-line option parser --- Jim Freeze wrote: > In one way what you are suggesting is just a serialization > method, it just so happens that you are suggesting a string > be used > to store the serialized data. > > obj.to_s.from_s == obj #=> true With my proposal you would write the above as: obj.class.from_s(obj.to_s) == obj #=> true But, the intent is not to do something like Marshal does. I'm only proposiing klass.from_s methods where it makes sense, not for handling all classes like Marshal does. Only if you would want to parse an object of a certain type from a human readable/writable string would you want to make a from_s class method for that type. On top of that, Marshal really doesn't help with type conversion. It only converts from a type to a machine readable byte stream and back. It's kind of like changing the storage from memory to file like mmap does?? YAML seems similar too. > Which is essentially a serialization of obj, and is OO. > Right now, Marshal is functional > > Marshal.load(Mashal.dump(obj)) == obj #=> true > > One could argue that we have this, but with YAML. > YAML.load(obj.to_yaml) == obj #=> true > > So, why don't we add a #from_yaml or #yaml_load to every > object? I don't think I want this done automatically, but it > would be nice to have it available so I can extend a class or > object as needed. I'm not sure what that would buy you. > I think that every time we visit this subject, it goes back > to > similar arguments as to why every object doesn't have puts, > such as "fred".puts. Matz has made statements on this > which I agree with. Personally I think that puts("fred") is > more natural. It probably ends up like that because in C++ objects can write themselves out to a stream and read themselves in from a stream. I like what is there now too. I haven't used C++ in a while, so I can't say a whole lot about how it is managed (where the methods live). > But, I'm warming up to #from_s more and more, but still not > sure yet. Good. I'd like to know what you finally decide on for your command-line parser. > On 9/13/05, Eric Mahurin wrote: > > > From my perspective, the only reason for the distinction > > between Fixnum and Bignum is the efficiency (runtime and > > memory) of Fixnum - a very good benefit. Otherwise, I > think > > you should consider them the same. Many of the methods in > > Agreed > > -- > Jim Freeze > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com