Created
October 9, 2013 13:39
-
-
Save polycarpou/6901465 to your computer and use it in GitHub Desktop.
triangle todo day 13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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