Class: Point
- Inherits:
-
Object
- Object
- Point
- Defined in:
- lib/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#graphics_to_a ⇒ Object
Yay y,x standard!.
- #hash ⇒ Object
-
#initialize(x, y) ⇒ Point
constructor
A new instance of Point.
- #to_a ⇒ Object
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
#x ⇒ Object (readonly)
Returns the value of attribute x.
2 3 4 |
# File 'lib/point.rb', line 2 def x @x end |
#y ⇒ Object (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
25 26 27 |
# File 'lib/point.rb', line 25 def eql?(other) x == other.x && y == other.y end |
#graphics_to_a ⇒ Object
Yay y,x standard!
17 18 19 |
# File 'lib/point.rb', line 17 def graphics_to_a [y, x] end |
#hash ⇒ Object
21 22 23 |
# File 'lib/point.rb', line 21 def hash [x.hash, y.hash].hash end |
#to_a ⇒ Object
12 13 14 |
# File 'lib/point.rb', line 12 def to_a [x, y] end |