Class: Ruby::Node::Position

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/ruby/node/position.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row, col) ⇒ Position

Returns a new instance of Position.



8
9
10
11
# File 'lib/ruby/node/position.rb', line 8

def initialize(row, col)
  @row = row
  @col = col
end

Instance Attribute Details

#colObject

Returns the value of attribute col.



6
7
8
# File 'lib/ruby/node/position.rb', line 6

def col
  @col
end

#rowObject

Returns the value of attribute row.



6
7
8
# File 'lib/ruby/node/position.rb', line 6

def row
  @row
end

Instance Method Details

#<=>(other) ⇒ Object



17
18
19
# File 'lib/ruby/node/position.rb', line 17

def <=>(other)
  row < other.row ? -1 : row > other.row ?  1 : col <=> other.col
end

#==(other) ⇒ Object Also known as: eql?



21
22
23
# File 'lib/ruby/node/position.rb', line 21

def ==(other)
  to_a == other.to_a
end

#[](ix) ⇒ Object



13
14
15
# File 'lib/ruby/node/position.rb', line 13

def [](ix)
  ix == 0 ? row : col
end

#inspectObject



30
31
32
# File 'lib/ruby/node/position.rb', line 30

def inspect
  to_a.inspect
end

#to_aObject



26
27
28
# File 'lib/ruby/node/position.rb', line 26

def to_a
  [row, col]
end