私はコード アカデミー ストリームを行っており、Ruby の経験が少しあります。関数にパラメーターcheck_angles(self)
が必要な理由がわかりません。self
私が混乱している理由は、呼び出されたときに self パラメータを関数に渡す理由がわからないからです。関数呼び出し (コード ブロックの最後の行) は暗黙的に self を渡しているようですが、関数は self をパラメータとして明示的に定義する必要があります。
どうしてこれなの?
class Triangle(object):
def __init__(self, angle1, angle2, angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3
number_of_sides = 3
def check_angles(self):
sum_angles = self.angle1 + self.angle2 + self.angle3
if sum_angles == 180:
return True
else:
return False
tri = Triangle(45,34,78)
tri.check_angles(EMPTY BUT WHY)