Class: SizedArray

Inherits:
Array show all
Defined in:
lib/diakonos/sized-array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capacity = 10, *args) ⇒ SizedArray

Returns a new instance of SizedArray



4
5
6
7
# File 'lib/diakonos/sized-array.rb', line 4

def initialize( capacity = 10, *args )
    @capacity = capacity
    super( *args )
end

Instance Attribute Details

#capacityObject (readonly)

Returns the value of attribute capacity



2
3
4
# File 'lib/diakonos/sized-array.rb', line 2

def capacity
  @capacity
end

Instance Method Details

#<<(item) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/diakonos/sized-array.rb', line 28

def <<( item )
    retval = super( item )
    if size > @capacity
        retval = shift
    end
    retval
end

#concat(other_array) ⇒ Object



16
17
18
19
20
# File 'lib/diakonos/sized-array.rb', line 16

def concat( other_array )
    super( other_array )
    resize
    self
end

#fill(*args) ⇒ Object



22
23
24
25
26
# File 'lib/diakonos/sized-array.rb', line 22

def fill( *args )
    retval = super( *args )
    resize
    self
end

#push(item) ⇒ Object



36
37
38
# File 'lib/diakonos/sized-array.rb', line 36

def push( item )
    self << item
end

#unshift(item) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/diakonos/sized-array.rb', line 40

def unshift( item )
    retval = super( item )
    if size > @capacity
        retval = pop
    end
    retval
end