数组查询器¶ ↑
将数组包装在 ArrayInquirer 中,可以更友好地检查其类似字符串的内容。
variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet]) variants.phone? # => true variants.tablet? # => true variants.desktop? # => false
方法
- A
实例公共方法
any?(*candidates) 链接
将 candidates 集合中的每个元素传递给 ArrayInquirer 集合。如果 ArrayInquirer 集合中的任何元素等于 candidates 集合中任何元素的字符串化或符号化形式,则该方法返回 true。
如果未提供 candidates 集合,则方法返回 true。
variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet]) variants.any? # => true variants.any?(:phone, :tablet) # => true variants.any?('phone', 'desktop') # => true variants.any?(:desktop, :watch) # => false
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/array_inquirer.rb, line 27 def any?(*candidates) if candidates.none? super else candidates.any? do |candidate| include?(candidate.to_sym) || include?(candidate.to_s) end end end