Now that the links are ok, fix the wording.
[ruby_koans.git] / src / triangle.rb
1 # Triangle Project Code.
2
3 # Triangle analyzes the lengths of the sides of a triangle
4 # (represented by a, b and c) and returns the type of triangle.
5 #
6 # It returns:
7 #   :equilateral  if all sides are equal
8 #   :isosceles    if exactly 2 sides are equal
9 #   :scalene      if no sides are equal
10 #
11 # The tests for this method can be found in
12 #   about_triangle_project.rb
13 # and
14 #   about_triangle_project_2.rb
15 #
16 def triangle(a, b, c)
17   # WRITE THIS CODE
18   #--
19   a, b, c = [a, b, c].sort
20   fail TriangleError if (a+b) <= c
21   sides = [a, b, c].uniq
22   [nil, :equilateral, :isosceles, :scalene][sides.size]
23   #++
24 end
25
26 # Error class used in part 2.  No need to change this code.
27 class TriangleError < StandardError
28 end