aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG.md4
-rw-r--r--activesupport/lib/active_support/core_ext/object/inclusion.rb4
-rw-r--r--activesupport/test/core_ext/object/inclusion_test.rb6
3 files changed, 7 insertions, 7 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index b3e8d1d2bd..edad34f343 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -26,7 +26,7 @@
*Jeremy Kemper*
-* Added `Object#present_in` to simplify value whitelisting.
+* Added `Object#presence_in` to simplify value whitelisting.
Before:
@@ -34,7 +34,7 @@
After:
- params[:bucket_type].present_in %w( project calendar )
+ params[:bucket_type].presence_in %w( project calendar )
*DHH*
diff --git a/activesupport/lib/active_support/core_ext/object/inclusion.rb b/activesupport/lib/active_support/core_ext/object/inclusion.rb
index 141f19e7b3..55f281b213 100644
--- a/activesupport/lib/active_support/core_ext/object/inclusion.rb
+++ b/activesupport/lib/active_support/core_ext/object/inclusion.rb
@@ -16,12 +16,12 @@ class Object
# Returns the receiver if it's included in the argument otherwise returns +nil+.
# Argument must be any object which responds to +#include?+. Usage:
#
- # params[:bucket_type].present_in %w( project calendar )
+ # params[:bucket_type].presence_in %w( project calendar )
#
# This will throw an ArgumentError if the argument doesn't respond to +#include?+.
#
# @return [Object]
- def present_in(another_object)
+ def presence_in(another_object)
self.in?(another_object) ? self : nil
end
end
diff --git a/activesupport/test/core_ext/object/inclusion_test.rb b/activesupport/test/core_ext/object/inclusion_test.rb
index c5e2cc693a..b054a8dd31 100644
--- a/activesupport/test/core_ext/object/inclusion_test.rb
+++ b/activesupport/test/core_ext/object/inclusion_test.rb
@@ -48,8 +48,8 @@ class InTest < ActiveSupport::TestCase
assert_raise(ArgumentError) { 1.in?(1) }
end
- def test_present_in
- assert_equal "stuff", "stuff".present_in(%w( lots of stuff ))
- assert_nil "stuff".present_in(%w( lots of crap ))
+ def test_presence_in
+ assert_equal "stuff", "stuff".presence_in(%w( lots of stuff ))
+ assert_nil "stuff".presence_in(%w( lots of crap ))
end
end