From: Nikolai Weibull Date: 2005-08-26T00:26:51+09:00 Subject: Re: idea: klass.from_s(str) Eric Mahurin wrote: > I was thinking how in seems a little asymmetric that many classes have > #to_s method, but when you want to make one of those objects from a > String, you have to clutter the String class with yet another #to_* > method. So the String class gets the burden of all those #to_* > methods. Instead, what if we would have the convention that creating > an object from a string would be a class method (for the class of that > object) instead of another String#to_* method. So, instead of these: > > String#to_i String#to_f > String#to_sym > String#to_ # where c is a abbreviation for the class > > you'd have these: > > Integer.from_s(str) > Float.from_s(str) > Symbol.from_s(str) > klass.from_s(str) How is i = Integer.from_s("123") better than i = "123".to_i? I prefer "send a message to the string to convert itself to something else" over "send a message to a class to convert the argument to an instance of that class", nikolai > klass.from_inspect(str) Kind of like read in Haskell or similar in Lisp?, nikolai -- Nikolai Weibull: now available free of charge at http://bitwi.se/! Born in Chicago, IL USA; currently residing in Gothenburg, Sweden. main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}