Skip to content

Instantly share code, notes, and snippets.

@tensiondriven
Created March 27, 2013 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tensiondriven/5250462 to your computer and use it in GitHub Desktop.
Save tensiondriven/5250462 to your computer and use it in GitHub Desktop.
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