Class: Table
- Inherits:
-
Object
- Object
- Table
- Defined in:
- lib/openrgss/table.rb
Overview
The multidimensional array class. Each element is an integer of 2 signed bytes ranging from -32,768 to 32,767.
Ruby’s Array class does not run efficiently when handling large amounts of data, hence the inclusion of this class.
Instance Attribute Summary collapse
-
#xsize ⇒ Object
readonly
Returns the value of attribute xsize.
-
#ysize ⇒ Object
readonly
Returns the value of attribute ysize.
-
#zsize ⇒ Object
readonly
Returns the value of attribute zsize.
Class Method Summary collapse
-
._load(s) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#[](x, y = 0, z = 0) ⇒ Object
:call-seq: self self[x, y] self[x, y, z].
-
#[]=(x, y = 0, z = 0, v) ⇒ Object
:nodoc:.
-
#_dump(d = 0) ⇒ Object
:nodoc:.
-
#initialize(xsize, ysize = 1, zsize = 1) ⇒ Table
constructor
Creates a Table object.
-
#resize(xsize, ysize = 1, zsize = 1) ⇒ Object
Changes the size of the array.
Constructor Details
#initialize(xsize, ysize = 1, zsize = 1) ⇒ Table
Creates a Table object. Specifies the size of each dimension in the multidimensional array. 1-, 2-, and 3-dimensional arrays are possible. Arrays with no parameters are also permitted.
10 11 12 13 14 15 |
# File 'lib/openrgss/table.rb', line 10 def initialize(xsize, ysize=1, zsize=1) @xsize = xsize @ysize = ysize @zsize = zsize @data = Array.new(@xsize*@ysize*@zsize, 0) end |
Instance Attribute Details
#xsize ⇒ Object (readonly)
Returns the value of attribute xsize.
6 7 8 |
# File 'lib/openrgss/table.rb', line 6 def xsize @xsize end |
#ysize ⇒ Object (readonly)
Returns the value of attribute ysize.
6 7 8 |
# File 'lib/openrgss/table.rb', line 6 def ysize @ysize end |
#zsize ⇒ Object (readonly)
Returns the value of attribute zsize.
6 7 8 |
# File 'lib/openrgss/table.rb', line 6 def zsize @zsize end |
Class Method Details
Instance Method Details
#[](x, y = 0, z = 0) ⇒ Object
:call-seq: self self[x, y] self[x, y, z]
Accesses the array’s elements. Pulls the same number of arguments as there are dimensions in the created array. Returns nil if the specified element does not exist.
30 31 32 33 |
# File 'lib/openrgss/table.rb', line 30 def [](x, y=0, z=0) return nil if x >= @xsize or y >= @ysize @data[x + y * @xsize + z * @xsize * @ysize] end |
#[]=(x, y = 0, z = 0, v) ⇒ Object
:nodoc:
35 36 37 |
# File 'lib/openrgss/table.rb', line 35 def []=(x, y=0, z=0, v) #:nodoc: @data[x + y * @xsize + z * @xsize * @ysize]=v end |
#_dump(d = 0) ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/openrgss/table.rb', line 48 def _dump(d = 0) #:nodoc: [@size, @xsize, @ysize, @zsize, @xsize*@ysize*@zsize, *@data].pack('LLLLLS*') end |
#resize(xsize, ysize = 1, zsize = 1) ⇒ Object
Changes the size of the array. All data from before the size change is retained.
19 20 21 |
# File 'lib/openrgss/table.rb', line 19 def resize(xsize, ysize=1, zsize=1) end |