Skip to content

Commit

Permalink
Revert "Remove Array#inquiry"
Browse files Browse the repository at this point in the history
This reverts commit 9420de5.

Reason: Turns out we want to keep this method.
  • Loading branch information
rafaelfranca committed Mar 30, 2015
1 parent cb01246 commit b5c3502
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Added `ActiveSupport::ArrayInquirer`.
* Added `ActiveSupport::ArrayInquirer` and `Array#inquiry`.

Wrapping an array in an `ArrayInquirer` gives a friendlier way to check its
contents:
Expand All @@ -13,6 +13,9 @@
variants.any?(:phone, :desktop) # => true
variants.any?(:desktop, :watch) # => false

`Array#inquiry` is a shortcut for wrapping the receiving array in an
`ArrayInquirer`.

*George Claghorn*

* Deprecate `alias_method_chain` in favour of `Module#prepend` introduced in Ruby 2.0
Expand Down
1 change: 1 addition & 0 deletions activesupport/lib/active_support/core_ext/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/array/grouping'
require 'active_support/core_ext/array/prepend_and_append'
require 'active_support/core_ext/array/inquiry'
15 changes: 15 additions & 0 deletions activesupport/lib/active_support/core_ext/array/inquiry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Array
# Wraps the array in an +ArrayInquirer+ object, which gives a friendlier way
# to check its string-like contents.
#
# pets = [:cat, :dog].inquiry
#
# pets.cat? # => true
# pets.ferret? # => false
#
# pets.any?(:cat, :ferret) # => true
# pets.any?(:ferret, :alligator) # => false
def inquiry
ActiveSupport::ArrayInquirer.new(self)
end
end
7 changes: 7 additions & 0 deletions activesupport/test/array_inquirer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ def test_any_with_block
def test_respond_to
assert_respond_to @array_inquirer, :development?
end

def test_inquiry
result = [:mobile, :tablet].inquiry

assert_instance_of ActiveSupport::ArrayInquirer, result
assert_equal @array_inquirer, result
end
end

0 comments on commit b5c3502

Please sign in to comment.