script or utility to transform a string w embedded spaces into a sym

I need to transform strings like "Instructor ID" or "Lovely Ice tree" into sym :instructor_id , :lovely_ice_tree I tried to do the following : downcase all string components the unique the spaces and replace w an underscore

is there a better and faster way to do it ?

thanks fy feedback

string.downcase.tr(' ', '_')

maybe.

I have a little monkey-patch called "dehumanize" which is *almost* what you want:

module ActiveSupport::Inflector   # does the opposite of humanize.... mostly. Basically does a   # space-substituting .underscore   def dehumanize(string_value)     result = string_value.to_s.dup     result.downcase.gsub(/ +/,'_')   end end class String   def dehumanize     ActiveSupport::Inflector.dehumanize(self)   end end

you could then call:   String.dehumanize.to_sym

Thanks , I'll use this patch ..

thanks , part of the solution as per Michael's patch