提交 c6ef49f4 编写于 作者: C Carlos Antonio da Silva

Revert "Merge pull request #10397 from BMorearty/remove-varargs-from-in-4-0-stable"

This reverts commit a8ef0bbb, reversing
changes made to 1296adb9.

Reason: Partially revert this commit and properly deprecate #in? with
multiple arguments in 4-0.
上级 adb005c3
## 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) ##
......
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
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册