Class: Toys::WrappableString
- Inherits:
-
Object
- Object
- Toys::WrappableString
- Defined in:
- core-docs/toys/wrappable_string.rb
Overview
Defined in the toys-core gem
A string intended for word-wrapped display.
Instance Attribute Summary collapse
-
#fragments ⇒ Array<String>
readonly
Returns the string fragments, i.e.
Class Method Summary collapse
-
.make(obj) ⇒ Toys::WrappableString
Make the given object a WrappableString.
-
.make_array(objs) ⇒ Array<Toys::WrappableString>
Make the given object an array of WrappableString.
-
.wrap_lines(strs, width, width2 = nil) ⇒ Array<String>
Wraps an array of lines to the given width.
Instance Method Summary collapse
-
#+(other) ⇒ WrappableString
Returns a new WrappaableString whose content is the concatenation of this WrappableString with another WrappableString.
-
#==(other) ⇒ Boolean
(also: #eql?)
Tests two wrappable strings for equality.
-
#empty? ⇒ Boolean
Returns true if the string is empty (i.e. has no fragments).
-
#hash ⇒ Integer
Returns a hash code for this object.
-
#initialize(string = "") ⇒ WrappableString
constructor
Create a wrapped string.
-
#string ⇒ String
(also: #to_s)
Returns the string without any wrapping.
-
#wrap(width, width2 = nil) ⇒ Array<String>
Wraps the string to the given width.
Constructor Details
#initialize(string = "") ⇒ WrappableString
Create a wrapped string.
13 14 15 |
# File 'core-docs/toys/wrappable_string.rb', line 13 def initialize(string = "") # Source available in the toys-core gem end |
Instance Attribute Details
#fragments ⇒ Array<String> (readonly)
Returns the string fragments, i.e. the individual "words" for wrapping.
22 23 24 |
# File 'core-docs/toys/wrappable_string.rb', line 22 def fragments @fragments end |
Class Method Details
.make(obj) ⇒ Toys::WrappableString
Make the given object a WrappableString. If the object is already a WrappableString, return it. Otherwise, treat it as a string or an array of strings and wrap it in a WrappableString.
106 107 108 |
# File 'core-docs/toys/wrappable_string.rb', line 106 def self.make(obj) # Source available in the toys-core gem end |
.make_array(objs) ⇒ Array<Toys::WrappableString>
Make the given object an array of WrappableString.
116 117 118 |
# File 'core-docs/toys/wrappable_string.rb', line 116 def self.make_array(objs) # Source available in the toys-core gem end |
.wrap_lines(strs, width, width2 = nil) ⇒ Array<String>
Wraps an array of lines to the given width.
93 94 95 |
# File 'core-docs/toys/wrappable_string.rb', line 93 def self.wrap_lines(strs, width, width2 = nil) # Source available in the toys-core gem end |
Instance Method Details
#+(other) ⇒ WrappableString
Returns a new WrappaableString whose content is the concatenation of this WrappableString with another WrappableString.
31 32 33 |
# File 'core-docs/toys/wrappable_string.rb', line 31 def +(other) # Source available in the toys-core gem end |
#==(other) ⇒ Boolean Also known as: eql?
Tests two wrappable strings for equality
57 58 59 |
# File 'core-docs/toys/wrappable_string.rb', line 57 def ==(other) # Source available in the toys-core gem end |
#empty? ⇒ Boolean
Returns true if the string is empty (i.e. has no fragments)
39 40 41 |
# File 'core-docs/toys/wrappable_string.rb', line 39 def empty? # Source available in the toys-core gem end |
#hash ⇒ Integer
Returns a hash code for this object
66 67 68 |
# File 'core-docs/toys/wrappable_string.rb', line 66 def hash # Source available in the toys-core gem end |
#string ⇒ String Also known as: to_s
Returns the string without any wrapping
47 48 49 |
# File 'core-docs/toys/wrappable_string.rb', line 47 def string # Source available in the toys-core gem end |
#wrap(width, width2 = nil) ⇒ Array<String>
Wraps the string to the given width.
79 80 81 |
# File 'core-docs/toys/wrappable_string.rb', line 79 def wrap(width, width2 = nil) # Source available in the toys-core gem end |