This is a personal memo.
By using the any? method, ** returns true if there is even one corresponding element in the target object **.
・object.any?{ |variable|Conditional expression}
・ Object.any?
** ▼ true case **
true1
arr = [1, 2, 3]
arr.any?{|x| x < 2}
=> true
** ▼ false case **
false1
arr = [1, 2, 3]
arr.any?{|x| x > 10}
=> false
** ▼ true case **
true1
arr = [1, 2, 3]
arr.any?
=> true
true2
arr = [nil, 2, nil]
arr.any?
=> true
false1
arr3 = []
arr3.any?
=> false
false2
arr4 = [nil, nil, nil]
arr4.any?
=> false
Recommended Posts