Ruby Koan 151 raising exceptions

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

    your previous triangle method should appear here

    class TriangleError < StandardError
    end
    
    def triangle(x,y,z)
      if(x>=y+z||y>=x+z||z>=x+y)
        raise TriangleError,"impossible triangle"
      elsif(x==0&&y==0&&z==0)||(x<0||y<0||z<0)
        raise TriangleError,"length cannot be zero or negative"
      elsif(x==y&&x==z)
        :equilateral
      elsif(x==y||y==z||x==z)
        :isosceles
      else
        :scalene
      end
    end
    

提交回复
热议问题