Solution: Calculate Shape Area
Go over how to model shapes and calculate their areas using inheritance.
We'll cover the following...
Solution
Press + to interact
class Shapeendclass Triangle < Shapeattr_accessor :base, :heightdef initialize(base, height)@base = base@height = heightenddef areareturn base * height / 2.0endendclass Rectangle < Shapeattr_accessor :width, :lengthdef initialize(length, width)@length = length@width = widthenddef areareturn length * widthendendclass Square < Rectangledef initialize(length)super(length, length)endendputs Triangle.new(10, 5).area()puts Rectangle.new(10, 5).area()puts Square.new(10).area()
Explanation
Line 34: The ...