Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only rescue a thrown NoMethodError, don't preemptively check for #inc…

…lude?; added tests
  • Loading branch information...
commit c54e60c3586c64475c17755eaafc76c840333fa8 1 parent 8f06e15
@jaredonline jaredonline authored
View
5 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
View
4 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
Please sign in to comment.
Something went wrong with that request. Please try again.