Skip to content

Instantly share code, notes, and snippets.

@thefonso
Created January 10, 2013 16:16
Show Gist options
  • Select an option

  • Save thefonso/4503336 to your computer and use it in GitHub Desktop.

Select an option

Save thefonso/4503336 to your computer and use it in GitHub Desktop.
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