我想出了以下针对公案的解决方案。
# and
# about_triangle_project_2.rb
#
def triangle(a, b, c)
driehoek = Array.new[ a, b, c].sort
raise (TriangleError), "length cannnot be 0 or lesser" if (driehoek[0] <= 0)
raise (TriangleError), "impossible triangle" if (driehoek[0] + driehoek[1] < driehoek[2])
return :equilateral if ((a == b) and (b == c))
return :isosceles if (((a == b) and (b != c)) or
((a != b) and (b == c)) or
((a == c) and (a != b)))
return :scalene if ((a !=b) and (b != c))
end
# Error class used in part 2. No need to change this code.
class TriangleError < StandardError
end
但是现在当使用三角形 [2,2,2] 时,我会看到以下错误消息:
The answers you seek...
wrong number of arguments (3 for 2)
Please meditate on the following code:
./triangle.rb:18:in `[]'
./triangle.rb:18:in `triangle'
谁能告诉我这里有什么问题?
罗洛夫