Skip to content

Instantly share code, notes, and snippets.

@sarony
Last active December 25, 2015 02:19
Show Gist options
  • Select an option

  • Save sarony/6901776 to your computer and use it in GitHub Desktop.

Select an option

Save sarony/6901776 to your computer and use it in GitHub Desktop.
class TriangleError < Exception
end
class Triangle
def initialize(side1, side2, side3)
@side1=side1
@side2=side2
@side3=side3
triangle?
end
def kind
return :equilateral if (@side1==@side2)&&(@side2==@side3)
(@side1==@side2)||(@side2==@side3)||(@side1==@side3) ? :isosceles : :scalene
end
def triangle?
sides=[@side1, @side2, @side3].sort!
if sides[2]<sides[1]+sides[0] && sides[0]>0
else
raise Exception::TriangleError
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment