Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Go with #presence_in instead of #present_in -- it doesnt sound quite …

…as good, but the closer relationship to #presence over #present is ultimately worth it
  • Loading branch information...
commit d61baee52adcd1baebe15f1065a0805857571f19 1 parent 3007c29
@dhh dhh authored
View
4 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*
View
4 activesupport/lib/active_support/core_ext/object/inclusion.rb
@@ -16,12 +16,12 @@ def in?(another_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
View
6 activesupport/test/core_ext/object/inclusion_test.rb
@@ -48,8 +48,8 @@ def test_no_method_catching
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
Please sign in to comment.
Something went wrong with that request. Please try again.