Created
August 21, 2011 07:24
-
-
Save Amitesh/1160287 to your computer and use it in GitHub Desktop.
Word wrap in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It works for pure text only. It will fail for html and url type of text. | |
# http://henrik.nyh.se/2007/03/ruby-wordwrap-method | |
def wrap_long_string(text,max_width = 20) | |
(text.length < max_width) ? | |
text : | |
text.scan(/.{1,#{max_width}}/).join("<wbr>") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment