Class: Rchess::Coord
- Inherits:
-
Object
- Object
- Rchess::Coord
- Defined in:
- lib/rchess/coord.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #apply_delta(delta) ⇒ Object
-
#initialize(h) ⇒ Coord
constructor
A new instance of Coord.
- #to_hash ⇒ Object
Constructor Details
#initialize(h) ⇒ Coord
Returns a new instance of Coord.
5 6 7 8 |
# File 'lib/rchess/coord.rb', line 5 def initialize(h) self.x = h.fetch(:x){ raise ArgumentError.new("Please provide a value for key :x") } self.y = h.fetch(:y){ raise ArgumentError.new("Please provide a value for key :y") } end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/rchess/coord.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/rchess/coord.rb', line 3 def y @y end |
Instance Method Details
#apply_delta(delta) ⇒ Object
10 11 12 |
# File 'lib/rchess/coord.rb', line 10 def apply_delta(delta) Coord.new({ x: (self.x + delta[:x]), y: (self.y + delta[:y]) }) end |
#to_hash ⇒ Object
14 15 16 |
# File 'lib/rchess/coord.rb', line 14 def to_hash { x: self.x, y: self.y } end |