From: Christian Neukirchen Date: 2005-12-13T05:06:08+09:00 Subject: Re: String.to_sym? mental@rydia.net writes: > Quoting robertj : > >> hi, >> >> is there a String#to_sym method anywhere in the >> statndard lib? i couldnt find anything like that >> but maybe i missed it. > > If you've got a reasonably recent version of Ruby, yes. I don't > know about 1.6 or earlier. > >> its easy enough to write >> >> class String >> def to_sym eval ":#{dump}" >> end >> end > > eval'ing ":#{self}" won't work if the string has spaces or anything > like that. In general, eval'ing strings should be an absolute last > resort in code, because it is very difficult to make reliable. > > -mental > -- Christian Neukirchen http://chneukirchen.org