Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

In Files

  • rubygems/text.rb

Methods

Class/Module Index [+]

Quicksearch

Gem::Text

A collection of text-wrangling methods

Public Instance Methods

format_text(text, wrap, indent=0) click to toggle source

Wraps text to wrap characters and optionally indents by indent characters

 
               # File rubygems/text.rb, line 12
def format_text(text, wrap, indent=0)
  result = []
  work = text.dup

  while work.length > wrap do
    if work =~ /^(.{0,#{wrap}})[ \n]/ then
      result << $1
      work.slice!(0, $&.length)
    else
      result << work.slice!(0, wrap)
    end
  end

  result << work if work.length.nonzero?
  result.join("\n").gsub(/^/, " " * indent)
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus