Reputation: 2982
Rails 2.3.5
I need a temp work around for a script that only has 1 possible styling. Is there a simple way to loop through a string and add line breaks? Like at every 80th character insert a '\n'? (really looping through a record set and doing this to a text field).
Thanks!
Upvotes: 3
Views: 4391
Reputation: 6322
Not sure this is the best approach.. but you could use each_slice here. Maybe something like:
"SOME AWESOME STRING".chars.each_slice(80).map(&:join).join('\n')
Upvotes: 2