aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/array_inquirer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/array_inquirer.rb')
-rw-r--r--activesupport/lib/active_support/array_inquirer.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/array_inquirer.rb b/activesupport/lib/active_support/array_inquirer.rb
index 0ae534da00..f59ddf5403 100644
--- a/activesupport/lib/active_support/array_inquirer.rb
+++ b/activesupport/lib/active_support/array_inquirer.rb
@@ -7,17 +7,23 @@ module ActiveSupport
# variants.phone? # => true
# variants.tablet? # => true
# variants.desktop? # => false
- #
- # variants.any?(:phone, :tablet) # => true
- # variants.any?(:phone, :desktop) # => true
- # variants.any?(:desktop, :watch) # => false
class ArrayInquirer < Array
+ # Passes each element of +candidates+ collection to ArrayInquirer collection.
+ # The method returns true if at least one element is the same. 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
def any?(*candidates, &block)
if candidates.none?
super
else
candidates.any? do |candidate|
- include?(candidate) || include?(candidate.to_sym)
+ include?(candidate.to_sym) || include?(candidate.to_s)
end
end
end