I have the following string and I would like to convert it to a hash printing the below result
string = "Cow, Bill, Phone, Flour"
hash = string.split(",")
>> {:animal => "Cow", :person: "Bill", :gadget => "Phone",
:grocery => "Flour"}
|
|
|||||||||||||
|
The answer by @Max is quite nice. You might understand it better as:
Here is a less sophisticated approach:
|
|||
|