Class: Rubydraw::Point
Overview
Used for specifying x and y positions in one class, instead of by themselves or arrays. Might look like:
@image.draw(Point[5, 6])
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
-
.[](x, y) ⇒ Object
Shorthand new method.
Instance Method Summary collapse
-
#initialize(x, y) ⇒ Point
constructor
Create a new point with the given
x
andy
positions.
Constructor Details
#initialize(x, y) ⇒ Point
Create a new point with the given x
and y
positions.
15 16 17 18 19 20 |
# File 'lib/rubydraw/point.rb', line 15 def initialize(x, y) unless x.is_a?(Numeric) and y.is_a?(Numeric) raise RuntimeError "New Point x and y must be a number." end @x, @y = x, y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
12 13 14 |
# File 'lib/rubydraw/point.rb', line 12 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
12 13 14 |
# File 'lib/rubydraw/point.rb', line 12 def y @y end |
Class Method Details
.[](x, y) ⇒ Object
Shorthand new method
8 9 10 |
# File 'lib/rubydraw/point.rb', line 8 def self.[](x, y) self.new(x, y) end |