I would use:
b = "123456789"
b.scan(/.{3}/) # => ["123", "456", "789"]
If the OP sample should have been of a different length or had a built-in "\ n", a simple modification works:
b = "123456789"
b.scan(/.{1,3}/) # => ["123", "456", "789"]
b[0..-2].scan(/.{1,3}/) # => ["123", "456", "78"]
"#{ b }\n#{ b }".scan(/.{1,3}/) # => ["123", "456", "789", "123", "456", "789"]
Now, if there is a built-in "\ n" NOT on the even border of "3", it is interrupted:
"#{ b[0..-2] }\n#{ b }".scan(/.{1,3}/) # => ["123", "456", "78", "123", "456", "789"]
OP :
"#{ b[0..-2] }\n#{ b }".delete("\n").scan(/.{1,3}/) # => ["123", "456", "781", "234", "567", "89"]