Class: Sqreen::Util::CappedArray
- Inherits:
-
Array
- Object
- Array
- Sqreen::Util::CappedArray
- Defined in:
- lib/sqreen/util/capped_array.rb
Instance Attribute Summary collapse
-
#depth_cap ⇒ Object
readonly
Returns the value of attribute depth_cap.
-
#size_cap ⇒ Object
readonly
Returns the value of attribute size_cap.
Instance Method Summary collapse
- #<<(value) ⇒ Object (also: #append)
- #[]=(index, value) ⇒ Object
-
#initialize(*args, &block) ⇒ CappedArray
constructor
A new instance of CappedArray.
Constructor Details
#initialize(*args, &block) ⇒ CappedArray
Returns a new instance of CappedArray.
11 12 13 14 15 16 17 18 19 |
# File 'lib/sqreen/util/capped_array.rb', line 11 def initialize(*args, &block) opts = args.last.is_a?(Hash) ? args.pop : {} size_cap = opts[:size_cap] || 150 depth_cap = opts[:depth_cap] || 10 @size_cap = size_cap @depth_cap = depth_cap super(*args, &block) end |
Instance Attribute Details
#depth_cap ⇒ Object (readonly)
Returns the value of attribute depth_cap.
9 10 11 |
# File 'lib/sqreen/util/capped_array.rb', line 9 def depth_cap @depth_cap end |
#size_cap ⇒ Object (readonly)
Returns the value of attribute size_cap.
9 10 11 |
# File 'lib/sqreen/util/capped_array.rb', line 9 def size_cap @size_cap end |
Instance Method Details
#<<(value) ⇒ Object Also known as: append
21 22 23 |
# File 'lib/sqreen/util/capped_array.rb', line 21 def <<(value) keep?(size, value) ? super : self end |
#[]=(index, value) ⇒ Object
26 27 28 |
# File 'lib/sqreen/util/capped_array.rb', line 26 def []=(index, value) super if keep?(index, value) end |