diff --git a/activesupport/lib/active_support/core_ext/object/inclusion.rb b/activesupport/lib/active_support/core_ext/object/inclusion.rb index f30333fd02fb0c4c2d4b4f342970784c095baa82..51cfc62f2b01c0e1059c8a58677196ed7ece80bc 100644 --- a/activesupport/lib/active_support/core_ext/object/inclusion.rb +++ b/activesupport/lib/active_support/core_ext/object/inclusion.rb @@ -5,8 +5,11 @@ class Object # characters = ["Konata", "Kagami", "Tsukasa"] # "Konata".in?(characters) # => true # + # This will throw an ArgumentError if the supplied argument doesnt not respond + # to +#include?+. def in?(another_object) - raise ArgumentError.new("You must supply another object that responds to include?") unless another_object.respond_to?(:include?) another_object.include?(self) + rescue NoMethodError + raise ArgumentError.new("The parameter passed to #in? must respond to #include?") end end diff --git a/activesupport/test/core_ext/object/inclusion_test.rb b/activesupport/test/core_ext/object/inclusion_test.rb index 382271d42df70375c8c64bbdc545d161406f7c1b..1de857d67898ad7991c714b82df532a257f4470e 100644 --- a/activesupport/test/core_ext/object/inclusion_test.rb +++ b/activesupport/test/core_ext/object/inclusion_test.rb @@ -43,4 +43,8 @@ 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 end