We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

gdonald on 09/27/06


Tagged

breakup long lines


Versions (?)


Rails breakup long lines


Published in: Ruby 


  1. def break_up_long_line(str, max)
  2. counter = 0
  3. new_text = ''
  4. for i in 0...str.length
  5. if str[i,1] =~ /\n/
  6. counter = 0
  7. else
  8. counter = counter + 1
  9. end
  10. new_text << str[i,1]
  11. if counter >= max && str[i,1] =~ /\s/
  12. new_text << "\n"
  13. counter = 0
  14. end
  15. end
  16. new_text
  17. end

Report this snippet 

You need to login to post a comment.