문제

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!

도움이 되었습니까?

해결책

Array#flatten may help

foo = "bar = everybody\nbar = say\nbar = hey\nbar = ho"
foo.scan(/^bar = (.*)$/).flatten
#=> ["everybody", "say", "hey", "ho"]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top