Skip to content

Instantly share code, notes, and snippets.

@polycarpou
Created October 9, 2013 13:39
Show Gist options
  • Save polycarpou/6901465 to your computer and use it in GitHub Desktop.
Save polycarpou/6901465 to your computer and use it in GitHub Desktop.
triangle todo day 13
class Triangle
attr_accessor :a, :b, :c
def initialize(a,b,c)
@a = a
@b = b
@c = c
end
def kind
if [self.a, self.b, self.c].any?{|x| x <= 0}
raise TriangleError
end
sorted_arr = [self.a, self.b, self.c].sort
p sorted_arr
if (sorted_arr[0]) + (sorted_arr[1]) <= (sorted_arr[2])
raise TriangleError
end
case [self.a, self.b, self.c].uniq.count
when 1
:equilateral
when 2
:isosceles
when 3
:scalene
end
end
end
class TriangleError < Exception
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment