Class: SizedArray
Instance Attribute Summary (collapse)
-
- (Object) capacity
readonly
Returns the value of attribute capacity.
Instance Method Summary (collapse)
- - (Object) <<(item)
- - (Object) concat(other_array)
- - (Object) fill(*args)
-
- (SizedArray) initialize(capacity = 10, *args)
constructor
A new instance of SizedArray.
- - (Object) push(item)
- - (Object) unshift(item)
Constructor Details
- (SizedArray) initialize(capacity = 10, *args)
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
- (Object) capacity (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
- (Object) <<(item)
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 |
- (Object) concat(other_array)
16 17 18 19 20 |
# File 'lib/diakonos/sized-array.rb', line 16 def concat( other_array ) super( other_array ) resize self end |
- (Object) fill(*args)
22 23 24 25 26 |
# File 'lib/diakonos/sized-array.rb', line 22 def fill( *args ) retval = super( *args ) resize self end |
- (Object) push(item)
36 37 38 |
# File 'lib/diakonos/sized-array.rb', line 36 def push( item ) self << item end |
- (Object) unshift(item)
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 |