Class: Rubydraw::Point

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

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

Class Method Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

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