Class: OrderedRow
- Inherits:
-
Object
- Object
- OrderedRow
- Defined in:
- lib/tablestakes.rb
Overview
This class functions as a temporary representation of a row. The OrderedRow contains information about which column it should be sorted on, so that Comparable can be implemented.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Implements comparable.
-
#data ⇒ Object
Returns the row elements in an
Array
. -
#initialize(my_array, index) ⇒ OrderedRow
constructor
Creates a new OrderedRow.
Constructor Details
#initialize(my_array, index) ⇒ OrderedRow
Creates a new OrderedRow. Callers must specify the index of the row element which will be used for order comparisons.
Attributes
my_array
-
An array representing a row from
Table
index
-
A Fixnum value which represents the comparison value
711 712 713 714 |
# File 'lib/tablestakes.rb', line 711 def initialize(my_array, index) @data = my_array @sort_index = index end |
Instance Method Details
#<=>(other) ⇒ Object
Implements comparable
Attributes
other
-
The row to be compared
728 729 730 |
# File 'lib/tablestakes.rb', line 728 def <=>(other) self.data[@sort_index] <=> other.data[@sort_index] end |
#data ⇒ Object
Returns the row elements in an Array
Attributes
none
720 721 722 |
# File 'lib/tablestakes.rb', line 720 def data return @data end |