ruby on rails - How to create hash out of specific words in text? -


i have file following content:

class rename < activerecord::migration   def change     rename_table :users, :vendors     rename_table :places, :venues      #there loads of similar lines   end end 

and need create hash following structure:

{ "users" => "vendors",   "places" => "venues" } 

how can achieve this?

i can fetch needed words using regular expression method scan /rename_table.:(\s+),\s:(\s+)/, returns

[["users", "vendors"], ["places", "venues"]] 

[["users", "vendors"], ["places", "venues"]].to_h  => {"users"=>"vendors", "places"=>"venues"}  

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -