How do I convert a string into hash in Ruby? -


I have a file with a value separated by location:

  Paul Smith 12345678 John doe 23456789  

and it needs to be changed to a hash like this:

  {"Paul Smith" => "12345678", "Louis S. Elena Blisset 34567890  
"23456789", "Lucy S. Alana Blisset" => "34567890"}

I can follow for CSV but stumped with little CST and new line characters.

Thanks for any help!

 

s = & lt; & Lt; _ Paul Smith 12345678 John Alex du 23456789 Lucy S. Alana Blisset 34567890 _ s.scan (/ (. +) (. +) /) To_h

Result:

  {"Paul Smith" => "12345678", "John Alex Do" = gt; "23456789", "Lucy S. Alana Blisset" => "34567890"}  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -