返回一个数组,每个元素是一个单词:
words = string.split(' ')
我想要返回一个数组,每个元素是2个字.
str = 'one two three four five six seven' str.split.each_slice(2).map{|a|a.join ' '} => ["one two","three four","five six","seven"]
这也处理了奇数个字的情况.