Class: Cotcube::Indicators::Carrier
- Inherits:
-
Object
- Object
- Cotcube::Indicators::Carrier
- Defined in:
- lib/cotcube-indicators/__carrier.rb
Instance Method Summary collapse
- #<<(obj) ⇒ Object
- #[](key) ⇒ Object
- #clear ⇒ Object
- #empty? ⇒ Boolean
- #get ⇒ Object
-
#initialize(length:) ⇒ Carrier
constructor
A new instance of Carrier.
- #shift ⇒ Object
- #size ⇒ Object (also: #length)
Constructor Details
#initialize(length:) ⇒ Carrier
Returns a new instance of Carrier.
6 7 8 9 10 11 |
# File 'lib/cotcube-indicators/__carrier.rb', line 6 def initialize(length:) raise ArgumentError, 'Need a length to be an integer' unless length.is_a? Integer @length = length @content = [] end |
Instance Method Details
#<<(obj) ⇒ Object
13 14 15 16 17 |
# File 'lib/cotcube-indicators/__carrier.rb', line 13 def <<(obj) @content << obj @content.shift if @content.length > @length obj end |
#[](key) ⇒ Object
42 43 44 |
# File 'lib/cotcube-indicators/__carrier.rb', line 42 def [](key) @content.map { |x| x[key] } end |
#clear ⇒ Object
25 26 27 |
# File 'lib/cotcube-indicators/__carrier.rb', line 25 def clear @content = [] end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/cotcube-indicators/__carrier.rb', line 38 def empty? @content.empty? end |
#get ⇒ Object
29 30 31 |
# File 'lib/cotcube-indicators/__carrier.rb', line 29 def get @content end |
#shift ⇒ Object
19 20 21 22 23 |
# File 'lib/cotcube-indicators/__carrier.rb', line 19 def shift @content.shift # sending explicit return to avoid returning a value here nil end |
#size ⇒ Object Also known as: length
33 34 35 |
# File 'lib/cotcube-indicators/__carrier.rb', line 33 def size @content.size end |