I am pretty much new to Ruby and I am looking at the best way to do the below.
I have a string like this "Account 1 - Name, Account 1 - Age, Account 2 - Name, Account 2 - Age"
I am looking for an output something like this
[[Account 1, Name], [Account 1, Age], [Account 2, Name], [Account 2, Age]]
Certainly I don't want to post the ways I tried as it looks silly and ugly. I am looking for a single liner if possible. Many thanks and appreciate all your help!
str.split(/ - |, /).each_slice(2).to_a.str.split(/ - |, /) #=> ["Account 1", "Name", "Account 1", "Age", "Account 2", "Name", "Account 2", "Age"]. See Enumerable#each_slice (the "no block given" case).