Class: Point

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Point

Returns a new instance of Point.



3
4
5
6
# File 'lib/point.rb', line 3

def initialize(x, y)
  @x = x
  @y = y
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



2
3
4
# File 'lib/point.rb', line 2

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



2
3
4
# File 'lib/point.rb', line 2

def y
  @y
end

Instance Method Details

#+(other) ⇒ Object



8
9
10
# File 'lib/point.rb', line 8

def +(other)
  Point.new(x + other.x, y + other.y)
end

#-(other) ⇒ Object



33
34
35
# File 'lib/point.rb', line 33

def -(other)
  Point.new(x - other.x, y - other.y)
end

#==(other) ⇒ Object



29
30
31
# File 'lib/point.rb', line 29

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/point.rb', line 25

def eql?(other)
  x == other.x && y == other.y
end

#graphics_to_aObject

Yay y,x standard!



17
18
19
# File 'lib/point.rb', line 17

def graphics_to_a
  [y, x]
end

#hashObject



21
22
23
# File 'lib/point.rb', line 21

def hash
  [x.hash, y.hash].hash
end

#to_aObject



12
13
14
# File 'lib/point.rb', line 12

def to_a
  [x, y]
end