Class: Position
- Inherits:
-
Object
- Object
- Position
- Defined in:
- lib/position.rb
Instance Attribute Summary collapse
-
#col ⇒ Object
readonly
Returns the value of attribute col.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(col, row) ⇒ Position
constructor
A new instance of Position.
- #next(direction) ⇒ Object
- #previous(direction) ⇒ Object
- #shift(offset, direction) ⇒ Object
Constructor Details
#initialize(col, row) ⇒ Position
Returns a new instance of Position.
6 7 8 9 |
# File 'lib/position.rb', line 6 def initialize(col, row) @col = col @row = row end |
Instance Attribute Details
#col ⇒ Object (readonly)
Returns the value of attribute col.
4 5 6 |
# File 'lib/position.rb', line 4 def col @col end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
4 5 6 |
# File 'lib/position.rb', line 4 def row @row end |
Instance Method Details
#==(other) ⇒ Object
27 28 29 |
# File 'lib/position.rb', line 27 def ==(other) [col, row] == [other.col, other.row] end |
#eql?(other) ⇒ Boolean
31 32 33 |
# File 'lib/position.rb', line 31 def eql?(other) [col, row].eql?([other.col, other.row]) end |
#hash ⇒ Object
35 36 37 |
# File 'lib/position.rb', line 35 def hash [col, row].hash end |
#next(direction) ⇒ Object
23 24 25 |
# File 'lib/position.rb', line 23 def next(direction) shift(1, direction) end |
#previous(direction) ⇒ Object
19 20 21 |
# File 'lib/position.rb', line 19 def previous(direction) shift(-1, direction) end |