Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Merge pull request #10397 from BMorearty/remove-varargs-from-…

…in-4-0-stable"

This reverts commit a8ef0bb, reversing
changes made to 1296adb.

Reason: Partially revert this commit and properly deprecate #in? with
multiple arguments in 4-0.
  • Loading branch information...
commit c273cb630872e2d4ff9af7baf2de0c79ac0c9dd7 1 parent ac5b051
@carlosantoniodasilva carlosantoniodasilva authored
View
4 activesupport/CHANGELOG.md
@@ -1,8 +1,8 @@
## unreleased ##
-* Remove multiple parameters support of `Object#in?`.
+* Deprecate multiple parameters support of `Object#in?`.
- *Brian Morearty*
+ *Brian Morearty + Carlos Antonio da Silva*
## Rails 4.0.0.rc1 (April 29, 2013) ##
View
19 activesupport/lib/active_support/core_ext/object/inclusion.rb
@@ -1,3 +1,5 @@
+require 'active_support/deprecation'
+
class Object
# Returns true if this object is included in the argument. Argument must be
# any object which responds to +#include?+. Usage:
@@ -7,9 +9,18 @@ class Object
#
# This will throw an ArgumentError if the argument doesn't respond
# to +#include?+.
- def in?(another_object)
- another_object.include?(self)
- rescue NoMethodError
- raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
+ def in?(*args)
+ if args.length > 1
+ ActiveSupport::Deprecation.warn "Calling #in? with multiple arguments is" \
+ " deprecated, please pass in an object that responds to #include? instead."
+ args.include? self
+ else
+ another_object = args.first
+ if another_object.respond_to? :include?
+ another_object.include? self
+ else
+ raise ArgumentError.new 'The single parameter passed to #in? must respond to #include?'
+ end
+ end
end
end
View
16 activesupport/test/core_ext/object/inclusion_test.rb
@@ -2,6 +2,20 @@
require 'active_support/core_ext/object/inclusion'
class InTest < ActiveSupport::TestCase
+ def test_in_multiple_args
+ assert_deprecated do
+ assert :b.in?(:a,:b)
+ assert !:c.in?(:a,:b)
+ end
+ end
+
+ def test_in_multiple_arrays
+ assert_deprecated do
+ assert [1,2].in?([1,2],[2,3])
+ assert ![1,2].in?([1,3],[2,1])
+ end
+ end
+
def test_in_array
assert 1.in?([1,2])
assert !3.in?([1,2])
@@ -43,7 +57,7 @@ def test_in_module
assert A.in?(C)
assert !A.in?(A)
end
-
+
def test_no_method_catching
assert_raise(ArgumentError) { 1.in?(1) }
end
Please sign in to comment.
Something went wrong with that request. Please try again.