Class: Sqreen::Util::CappedString
- Inherits:
-
String
- Object
- String
- Sqreen::Util::CappedString
- Defined in:
- lib/sqreen/util/capped_string.rb
Instance Attribute Summary collapse
-
#size_cap ⇒ Object
readonly
Returns the value of attribute size_cap.
Instance Method Summary collapse
- #<<(value) ⇒ Object (also: #concat)
-
#initialize(*args, &block) ⇒ CappedString
constructor
A new instance of CappedString.
Constructor Details
#initialize(*args, &block) ⇒ CappedString
Returns a new instance of CappedString.
11 12 13 14 15 16 |
# File 'lib/sqreen/util/capped_string.rb', line 11 def initialize(*args, &block) opts = args.last.is_a?(Hash) ? args.pop : {} size_cap = opts[:size_cap] || 4096 @size_cap = size_cap super(*args, &block) end |
Instance Attribute Details
#size_cap ⇒ Object (readonly)
Returns the value of attribute size_cap.
9 10 11 |
# File 'lib/sqreen/util/capped_string.rb', line 9 def size_cap @size_cap end |
Instance Method Details
#<<(value) ⇒ Object Also known as: concat
18 19 20 21 22 23 24 |
# File 'lib/sqreen/util/capped_string.rb', line 18 def <<(value) return self unless size < size_cap value = value[0, size_cap - size] if size + value.size > size_cap super(value) end |