Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string.rb

Overview

Modify String class to allow for rsplit and word wrap

Instance Method Summary collapse

Instance Method Details

#rsplit(pattern) ⇒ Object



3
4
5
6
7
# File 'lib/string.rb', line 3

def rsplit(pattern)
    ret = rpartition(pattern)
    ret.delete_at(1)
    return ret
end

#word_wrap(width = 80) ⇒ Object



9
10
11
# File 'lib/string.rb', line 9

def word_wrap(width = 80)
    return scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/).join("\n")
end