Skip to content

Instantly share code, notes, and snippets.

@solomon081
Created March 27, 2012 02:48
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 solomon081/2212057 to your computer and use it in GitHub Desktop.
Save solomon081/2212057 to your computer and use it in GitHub Desktop.
Shape Class
class Shape
def initialize(sides, perimiter, name)
@name = name
@sides = sides
@perimiter = perimiter
puts "Shape Name: #@name"
puts "Sides: #@sides"
puts "Perimiter: #@perimiter"
puts "Avg. Side Length: " + (@perimiter.to_i/@sides.to_i).to_s
if @sides.to_i < 3 or @perimiter.to_i <= 0
puts "This shape is impossible!"
end
end
end
pentagon = Shape.new('5', '30', "Pentagon One")
square = Shape.new('4', '50', "Shape One")
invalid = Shape.new('2', '3', "Invalid Shape")
invalid2 = Shape.new("4", '-1', "Invalid Two")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment