Rubyを初めて使用しました。 Arrowheadプログラミングを削除して例外を発生させる私の練習の1つ。私はundefined method for validate_region_and_shape
を得続けます。Ruby:未定義のメソッドエラーを取得するNoMethodError
def self.classify(region, shape)
# Alternative for raising exception within classify method
#raise Error_Message unless CLASSIFICATIONS.include? (region)
#raise Error_Message unless CLASSIFICATIONS[region].include? (shape)
if validate_region_and_shape(region, shape)
places = CLASSIFICATIONS[region][shape]
"You have a(n) '#{places}'"
end
end
def validate_region_and_shape(region, shape)
raise Error_Message if valid_region?
raise Error_Message if valid_shape?
end
def valid_region?
CLASSIFICATIONS.include?(region)
end
def valid_shape?
CLASSIFICATIONS[region].include?(shape)
end
end
ご協力いただければ幸いです。
...それ最初のもののようなクラスメソッドにする必要があります。字下げは、 'def'sが' def self.classify'の中にあるように見せます。コードを大幅に変更しても、新しいコードには元の問題はありません。あなたが何を求めているのかは不明です。 – Schwern
また、 'valid_region?'メソッドはargとして 'region'を取り、同様に' valid_shape'は 'shape'を取るべきですか? – Rashmirathi