Skip to content
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...
1 parent 25a0572 commit c4bc2df29456b5d995fc2c390d89872f8fe988a1 @dhh dhh committed Feb 24, 2014
View
2 Gemfile
@@ -53,7 +53,7 @@ platforms :ruby do
gem 'sqlite3', '~> 1.3.6'
group :db do
- gem 'pg', '>= 0.11.0'
+ # gem 'pg', '>= 0.11.0'
gem 'mysql', '>= 2.9.0'
gem 'mysql2', '>= 0.3.13'
end
View
4 activesupport/CHANGELOG.md
@@ -1,12 +1,12 @@
-* Added `Object#present_in` to simplify value whitelisting.
+* Added `Object#presence_in` to simplify value whitelisting.
Before:
params[:bucket_type].in?(%w( project calendar )) ? params[:bucket_type] : nil
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

0 comments on commit c4bc2df

Please sign in to comment.
Something went wrong with that request. Please try again.