Class: Sugpoko::Point

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Point

Returns a new instance of Point.



5
6
7
8
9
10
11
# File 'lib/sugpoko/point.rb', line 5

def initialize(*args)
  if args[0].is_a?(Hash)
    @x, @y = identify(args[0])
  else
    @x, @y = identify(args)
  end
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#+(obj) ⇒ Object



13
14
15
16
# File 'lib/sugpoko/point.rb', line 13

def +(obj)
  id_x, id_y = identify obj
  self.class.new x + id_x, y + id_y
end

#-(obj) ⇒ Object



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

def -(obj)
  self.class.new x - obj.x, y - obj.y
end

#==(obj) ⇒ Object



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

def ==(obj)
  x == obj.x && y == obj.y
end

#to_aryObject



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

def to_ary
  [x, y]
end

#to_sObject



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

def to_s
  "[#{x}, #{y}]"
end