Array Inquirer
用 ArrayInquirer
包住陣列會更方便地檢查陣列中字串相關的內容
variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
variants.phone? # => true
variants.tablet? # => true
variants.desktop? # => false
方法
- A
執行個體公開的方法
any?(*candidates) 連結
將 candidates
集合的每個元素傳遞給 ArrayInquirer
集合。
如果 ArrayInquirer
集合中的任何元素都等於 candidates
集合中任何元素的字串化或符號化形式,方法就會傳回真值。
如果沒有提供 candidates
集合,方法會傳回真值。
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