I want to convert a string based on a hash. For e.g., the string "assistant director" gets converted to "asst dir" when the hash contains "assistant"=>"asst" and "director"=>"dir". I want to do something like:
hash = Hash["executive"=>"exec","assistant"=>"asst","associate"=>"assoc","director"=>"dir"]
str = "assistant director"
hash.each { |k, v| str.gsub!(k, v) }
# => "asst dir"
Based on this post,
hash.each { |k, v| str.gsub!(k, v) }
should be the answer. But it doesn't return the converted string. And neither does str get changed.