Class: Rect

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

Overview

The rectangle class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, width, height) ⇒ Rect

Returns a new instance of Rect.



15
16
17
# File 'lib/rect.rb', line 15

def initialize(x, y, width, height)
  set x, y, width, height
end

Instance Attribute Details

#heightObject

The rectangle’s height.



13
14
15
# File 'lib/rect.rb', line 13

def height
  @height
end

#widthObject

The rectangle’s width.



10
11
12
# File 'lib/rect.rb', line 10

def width
  @width
end

#xObject

The X-coordinate of the rectangle’s upper left corner.



4
5
6
# File 'lib/rect.rb', line 4

def x
  @x
end

#yObject

The Y-coordinate of the rectange’s upper left corner.



7
8
9
# File 'lib/rect.rb', line 7

def y
  @y
end

Instance Method Details

#set(x, y, width, height) ⇒ Object

Sets all parameters at once.



20
21
22
23
24
25
# File 'lib/rect.rb', line 20

def set(x, y, width, height)
  @x = x
  @y = y
  @width = width
  @height = height    
end