Class: Point

Inherits:
Struct
  • Object
show all
Defined in:
lib/pieces.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



75
76
77
# File 'lib/pieces.rb', line 75

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of y



75
76
77
# File 'lib/pieces.rb', line 75

def y
  @y
end

Instance Method Details

#+(other) ⇒ Object



76
77
78
# File 'lib/pieces.rb', line 76

def +(other)
  Point[y + other.y, x + other.x]
end

#-(other = nil) ⇒ Object



80
81
82
83
# File 'lib/pieces.rb', line 80

def -(other = nil)
  return Point[-y, -x] if other.nil?
  Point[y - other.y, x - other.x]
end