Ruby Koan 151 raising exceptions

后端 未结 30 1597
孤独总比滥情好
孤独总比滥情好 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:15

    I like Cory's answer. But I wonder if there's any reason or anything to gain by having four tests, when you could have two:

    raise TriangleError, "Sides must by numbers greater than zero" if (a <= 0) || (b <= 0) || (c <= 0)
    raise TriangleError, "No two sides can add to be less than or equal to the other side" if (a+b <= c) || (a+c <= b) || (b+c <= a)
    

提交回复
热议问题