Class: GGLib::CArray
- Inherits:
-
Array
- Object
- Array
- GGLib::CArray
- Defined in:
- lib/carray.rb
Overview
CArray is an Array which does not compact. CArrays place a priority on preserving the indices of each element in order to allow identification of elements thier indices. CArrays are used by the Window and Tile classes.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #compact ⇒ Object
- #compact! ⇒ Object
- #delete(obj) ⇒ Object
- #delete_at(loc) ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ CArray
constructor
A new instance of CArray.
- #pp ⇒ Object
- #push(item) ⇒ Object
Constructor Details
#initialize ⇒ CArray
Returns a new instance of CArray.
9 10 11 12 |
# File 'lib/carray.rb', line 9 def initialize @intsize=0 super end |
Instance Method Details
#<<(item) ⇒ Object
18 19 20 21 22 |
# File 'lib/carray.rb', line 18 def <<(item) self[@intsize]=item @intsize+=1 return @intsize-1 end |
#compact ⇒ Object
63 64 65 |
# File 'lib/carray.rb', line 63 def compact return false end |
#compact! ⇒ Object
66 67 68 |
# File 'lib/carray.rb', line 66 def compact! return false end |
#delete(obj) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/carray.rb', line 32 def delete(obj) if obj!=nil i=0 while i<=@intsize if self[i] == obj self[i]=nil end i+1 end else return nil end end |
#delete_at(loc) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/carray.rb', line 45 def delete_at(loc) if loc<@intsize self[loc]=nil end return self[loc+1] end |
#each ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/carray.rb', line 23 def each i=0 while i<=@intsize if self[i] !=nil yield self[i] end i+=1 end end |
#pp ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/carray.rb', line 51 def pp puts "CArray: " i=0 while i<=@intsize if self[i] !=nil puts i.to_s+"\t"+self[i].to_s else puts i.to_s+"\tnil" end i+=1 end end |
#push(item) ⇒ Object
13 14 15 16 17 |
# File 'lib/carray.rb', line 13 def push(item) self[@intsize]=item @intsize+=1 return @intsize-1 end |