Class: ActiveSupport::ArrayInquirer
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
| 
         Class Chain: 
        
          self,
           
      ::Array
         | 
    |
| 
         Instance Chain: 
        
          self,
           
      ::Array
         | 
    |
| Inherits: | Array | 
| Defined in: | activesupport/lib/active_support/array_inquirer.rb | 
Overview
Wrapping an array in an ArrayInquirer gives a friendlier way to check its string-like contents:
variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
variants.phone?    # => true
variants.tablet?   # => true
variants.desktop?  # => false
  Class Method Summary
::Array - Inherited
| .wrap | Wraps its argument in an array unless it is already an array (or array-like).  | 
    
Instance Method Summary
- 
    
      #any?(*candidates)  ⇒ Boolean 
    
    
Passes each element of
candidatescollection toArrayInquirercollection. 
::Array - Inherited
| #append | The human way of thinking about adding stuff to the end of a list is with append.  | 
    
| #blank? | An array is blank if it’s empty:  | 
    
| #deep_dup | Returns a deep copy of array.  | 
    
| #extract_options! | Extracts options from a set of arguments.  | 
    
| #fifth | Equal to   | 
    
| #forty_two | Equal to   | 
    
| #fourth | Equal to   | 
    
| #from | Returns the tail of the array from   | 
    
| #in_groups | Splits or iterates over the array in   | 
    
| #in_groups_of | Splits or iterates over the array in groups of size   | 
    
| #inquiry | Wraps the array in an   | 
    
| #prepend | The human way of thinking about adding stuff to the beginning of a list is with prepend.  | 
    
| #second | Equal to   | 
    
| #second_to_last | Equal to   | 
    
| #split | Divides the array into one or more subarrays based on a delimiting   | 
    
| #third | Equal to   | 
    
| #third_to_last | Equal to   | 
    
| #to | Returns the beginning of the array up to   | 
    
| #to_default_s, | |
| #to_formatted_s | Extends Array#to_s to convert a collection of elements into a comma separated id list if   | 
    
| #to_param | Calls   | 
    
| #to_query | Converts an array into a string suitable for use as a URL query string, using the given   | 
    
| #to_s | Alias for Array#to_formatted_s.  | 
    
| #to_sentence | Converts the array to a comma-separated sentence where the last element is joined by the connector word.  | 
    
| #to_xml | Returns a string that represents the array in XML by invoking   | 
    
| #without | Returns a copy of the   | 
    
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) (private)
[ GitHub ]# File 'activesupport/lib/active_support/array_inquirer.rb', line 40
def method_missing(name, *args) if name[-1] == "?" any?(name[0..-2]) else super end end
Instance Method Details
    #any?(*candidates)  ⇒ Boolean 
  
Passes each element of candidates collection to ArrayInquirer collection. The method returns true if any element from the ArrayInquirer collection is equal to the stringified or symbolized form of any element in the candidates collection.
If candidates collection is not given, method returns 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
  # File 'activesupport/lib/active_support/array_inquirer.rb', line 25
def any?(*candidates) if candidates.none? super else candidates.any? do |candidate| include?(candidate.to_sym) || include?(candidate.to_s) end end end