Class: Rectangle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(side_one, side_two) ⇒ Rectangle

Returns a new instance of Rectangle.



28
29
30
31
32
33
# File 'lib/shapelib.rb', line 28

def initialize(side_one, side_two)
  @side_one, @side_two = side_one, side_two
  @area = side_one * side_two
  @perimiter = (side_one * 2) + (side_two * 2)
  @diagonal = Math.sqrt(side_one ** 2 + side_two ** 2)
end

Instance Attribute Details

#areaObject (readonly)

Returns the value of attribute area.



26
27
28
# File 'lib/shapelib.rb', line 26

def area
  @area
end

#diagonalObject (readonly)

Returns the value of attribute diagonal.



26
27
28
# File 'lib/shapelib.rb', line 26

def diagonal
  @diagonal
end

#perimiterObject (readonly)

Returns the value of attribute perimiter.



26
27
28
# File 'lib/shapelib.rb', line 26

def perimiter
  @perimiter
end

Instance Method Details

#side_one=(val) ⇒ Object



43
44
45
46
# File 'lib/shapelib.rb', line 43

def side_one=(val)
  @side_one = val
  recalc
end

#side_two=(val) ⇒ Object



48
49
50
51
# File 'lib/shapelib.rb', line 48

def side_two=(val)
  @side_two = val
  recalc
end

#to_sObject



53
54
55
# File 'lib/shapelib.rb', line 53

def to_s
  "Rectangle: #{@side_one}-#{@side_two}"
end