はじめに
all?というメソッドを見つけました。
私的には少し使い方が変わっていると感じました。とても便利なので記事で残しておきます。
all?メソッド
配列に対して使用します。(配列でなくてもいいのかも?)
all?の後に{}を用意し、その中にブロック変数と条件式を記述します。
ブロック変数にall?直前の配列の要素を一つずつ放り込み、その配列の全ての要素が条件式でtrue 真だったときに初めてtrueを返します。
一つでもfalse 偽があるとfalseを返します。
array = [1, 2, 3, 4, 5, 6]
array.all?{|x| x > 0 }
=> true
array = [0, 1, 2, 3, 4, 5, 6]
array.all?{|x| x > 0 }
=> false
参考: https://docs.ruby-lang.org/ja/latest/method/Enumerable/i/all=3f.html