Class: TextWrapper

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

Constant Summary collapse

@@kwargs =
[
  :width,
  :expand_tabs,
  :replace_whitespace,
  :initial_indent,
  :subsequent_indent,
  :break_long_words,
  :consider_linebreak_whitespace,
  :code
]

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TextWrapper

Returns a new instance of TextWrapper.



136
137
138
139
140
141
# File 'lib/textwrap.rb', line 136

def initialize(options = {})
  @@kwargs.each do |kw|
    next unless options.has_key?(kw)
    self.instance_variable_set("@#{kw}", options[kw])
  end
end

Instance Method Details

#fill(text, width = nil, options = {}) ⇒ Object



149
150
151
152
153
# File 'lib/textwrap.rb', line 149

def fill(text, width = nil, options = {})
  prepare(text, width, options) do |t, w, o|
    Textwrap.fill(t, w, o)
  end
end

#wrap(text, width = nil, options = {}) ⇒ Object



143
144
145
146
147
# File 'lib/textwrap.rb', line 143

def wrap(text, width = nil, options = {})
  prepare(text, width, options) do |t, w, o|
    Textwrap.wrap(t, w, o)
  end
end