Class: SizedArray

Inherits:
Array
  • Object
show all
Defined in:
lib/ver/vendor/sized_array.rb

Overview

The MIT Licence

Copyright © 2004-2009 Pistos

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SizedArray.



26
27
28
29
# File 'lib/ver/vendor/sized_array.rb', line 26

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

Instance Attribute Details

#capacityObject (readonly)

Returns the value of attribute capacity.



24
25
26
# File 'lib/ver/vendor/sized_array.rb', line 24

def capacity
  @capacity
end

Instance Method Details

#<<(item) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/ver/vendor/sized_array.rb', line 50

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

#concat(other_array) ⇒ Object



38
39
40
41
42
# File 'lib/ver/vendor/sized_array.rb', line 38

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

#fill(*args) ⇒ Object



44
45
46
47
48
# File 'lib/ver/vendor/sized_array.rb', line 44

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

#push(item) ⇒ Object



58
59
60
# File 'lib/ver/vendor/sized_array.rb', line 58

def push( item )
  self << item
end

#unshift(item) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/ver/vendor/sized_array.rb', line 62

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