bradbajuz
bradbajuz

Reputation: 185

Convert Multidimensional Array Into Individual Strings in Ruby

I want to take a multidimensional array:

m_array = [["S39.91", "S39.91"], ["B99.9"]]

And convert it to individual strings based on its grouping:

String One = "S39.91, S39.91"
String Two = "B99.9"

Upvotes: 2

Views: 444

Answers (1)

user419017
user419017

Reputation:

What about:

m_array.map { |strings| strings.join(', ') }

That will give you an array:

["S39.91, S39.91", "B99.9"]

Which you can then use to assign to variables:

string_1, string_2 = ["S39.91, S39.91", "B99.9"]

Upvotes: 5

Related Questions