Class: Sugpoko::Point
- Inherits:
-
Object
- Object
- Sugpoko::Point
- Defined in:
- lib/sugpoko/point.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
- #+(obj) ⇒ Object
- #-(obj) ⇒ Object
- #==(obj) ⇒ Object
-
#initialize(*args) ⇒ Point
constructor
A new instance of Point.
- #to_ary ⇒ Object
- #to_s ⇒ Object
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
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/sugpoko/point.rb', line 3 def x @x end |
#y ⇒ Object
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_ary ⇒ Object
30 31 32 |
# File 'lib/sugpoko/point.rb', line 30 def to_ary [x, y] end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/sugpoko/point.rb', line 26 def to_s "[#{x}, #{y}]" end |