class ActiveSupport::ArrayInquirer
variants.desktop? # => false
variants.tablet? # => true
variants.phone? # => true
variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
its string-like contents:
Wrapping an array in an ArrayInquirer
gives a friendlier way to check
= Array Inquirer
def any?(*candidates)
variants.any?('phone', 'desktop') # => true
variants.any?(:phone, :tablet) # => true
variants.any? # => true
variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
If +candidates+ collection is not given, method returns true.
is equal to the stringified or symbolized form of any element in the +candidates+ collection.
The method returns true if any element from the ArrayInquirer collection
Passes each element of +candidates+ collection to ArrayInquirer collection.
def any?(*candidates) if candidates.none? super else candidates.any? do |candidate| include?(candidate.to_sym) || include?(candidate.to_s) end end end
def method_missing(name, *args)
def method_missing(name, *args) if name.end_with?("?") any?(name[0..-2]) else super end end
def respond_to_missing?(name, include_private = false)
def respond_to_missing?(name, include_private = false) name.end_with?("?") || super end