aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJared McFarland <jared.online@gmail.com>2011-04-15 00:04:21 +0800
committerDavid Heinemeier Hansson <david@loudthinking.com>2011-04-15 00:36:07 +0800
commitcd233dd87e6f0f9113a397531d37075cfa7c6526 (patch)
treebc800435a8d17a3a910c01f6e469d175ee5e2a56 /activesupport/lib
parent2db9f8a41c0e9d8978c0f6b80cb6efe5665168a7 (diff)
downloadrails-cd233dd87e6f0f9113a397531d37075cfa7c6526.tar.gz
rails-cd233dd87e6f0f9113a397531d37075cfa7c6526.tar.bz2
rails-cd233dd87e6f0f9113a397531d37075cfa7c6526.zip
Only rescue a thrown NoMethodError, don't preemptively check for #include?; added tests
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/object/inclusion.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/inclusion.rb b/activesupport/lib/active_support/core_ext/object/inclusion.rb
index f30333fd02..51cfc62f2b 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