Ruby Koan 151 raising exceptions

后端 未结 30 1628
孤独总比滥情好
孤独总比滥情好 2021-01-31 14:34

I\'m going through the ruby koans, I\'m on 151 and I just hit a brick wall.

Here is the koan:

# You need to write the triangle method in the file \'trian         


        
30条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-31 15:14

    No need to write the TriangleError method. It says 'No need to change this code', so I won't change it at all. Stubborn as I am.

    4lines shot it, nice nd clean.

        def triangle(a, b, c)
             if(a * b * c <= 0) || (( (a + c)<=b) || ((a + b)<=c)||((b + c)<=a) )
                 raise TriangleError else
                 return  ((a == b && b == c && a == c)?  :equilateral:(((a == b)||(b == c)||(a == c))?  :isosceles:  :scalene))
             end
        end
    
    
    # Error class used in part 2.  No need to change this code.
    class TriangleError < StandardError
    end
    

提交回复
热议问题