Created
January 10, 2013 16:16
-
-
Save thefonso/4503336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Rectangle | |
| attr_accessor :height, :width | |
| def area | |
| @height * @width | |
| end | |
| end | |
| class Square < Rectangle | |
| def height=(height) | |
| @side = height | |
| end | |
| def width=(width) | |
| @side = width | |
| end | |
| def area | |
| @side * @side | |
| end | |
| end | |
| class Program | |
| def initialize(name, height, width) | |
| if name == :square | |
| @shape = Square.new | |
| @shape.height = height | |
| else | |
| @shape = Rectangle.new | |
| @shape.height = height | |
| @shape.width = width | |
| end | |
| end | |
| def area | |
| @shape.area | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment