Ruby 2.5.0 リファレンスマニュアル > ライブラリ一覧 > matrixライブラリ > Matrixクラス > diagonal?
diagonal? -> bool
行列が対角行列ならば true を返します。