📜  ruby 对象是否存在于数组中 - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:46.910000             🧑  作者: Mango

代码示例1
# Element exists in array
object_exists = arr.any? { |elem| elem == desired_value }

# Element with property exists in array
object_exists = arr.any? { |obj| obj.prop == desired_value }

# Type exists in array
object_exists = arr.any?(Integer)

# Element matching regex exists in array
object_exists = arr.any?(/d/)