Created
March 27, 2013 00:04
-
-
Save tensiondriven/5250462 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 < Object | |
@@num_rects = 0 | |
attr_reader :width, :height | |
def initialize(width, height) | |
@width = width | |
@height = height | |
@@num_rects += 1 | |
end | |
def num_rects | |
@@num_rects | |
end | |
# def width | |
# @width | |
# end | |
# def height | |
# @height | |
# end | |
def area | |
@width * @height | |
end | |
end | |
class Square < Rectangle | |
def initialize(side) | |
super(side, side) | |
end | |
def area | |
@width**2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment