Question

I am trying to come up with a good way to do the following. I have a string, such as this one:

foo = "bar = everybody\nbar = say\nbar = hey\nbar = ho"

And I am scanning through it like this:

foo.scan(/^bar = (.*)$/)

That returns:

[["everybody"], ["say"], ["hey"], ["ho"]]

What I want is:

["everybody", "say", "hey", "ho"]

So basically, I would either like to remove the singleton dimension of the array or reformat the scan code.

Any ideas?

Thanks!

Was it helpful?

Solution

Array#flatten may help

foo = "bar = everybody\nbar = say\nbar = hey\nbar = ho"
foo.scan(/^bar = (.*)$/).flatten
#=> ["everybody", "say", "hey", "ho"]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top