diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 163f1c932c..69e9cbfd42 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.1.0 (unreleased)* +* Add String#inquiry as a convenience method for turning a string into a StringInquirer object [DHH] + * Add Object#in? to test if an object is included in another object [Prem Sichanugrist, Brian Morearty, John Reitano] * LocalCache strategy is now a real middleware class, not an anonymous class diff --git a/activesupport/lib/active_support/core_ext/string.rb b/activesupport/lib/active_support/core_ext/string.rb index 8fb8c31ade..72522d395c 100644 --- a/activesupport/lib/active_support/core_ext/string.rb +++ b/activesupport/lib/active_support/core_ext/string.rb @@ -11,3 +11,4 @@ require 'active_support/core_ext/string/output_safety' require 'active_support/core_ext/string/exclude' require 'active_support/core_ext/string/encoding' require 'active_support/core_ext/string/strip' +require 'active_support/core_ext/string/inquiry' diff --git a/activesupport/lib/active_support/core_ext/string/inquiry.rb b/activesupport/lib/active_support/core_ext/string/inquiry.rb new file mode 100644 index 0000000000..604f3bf4dc --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/inquiry.rb @@ -0,0 +1,13 @@ +require 'active_support/string_inquirer' + +class String + # Wraps the current string in the ActiveSupport::StringInquirer class, + # which gives you a prettier way to test for equality. Example: + # + # env = "production".inquiry + # env.production? # => true + # env.development? # => false + def inquiry + ActiveSupport::StringInquirer.new(self) + end +end diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index bb865cae91..f0c289a418 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -250,6 +250,11 @@ class StringInflectionsTest < Test::Unit::TestCase # And changes the original string: assert_equal original, expected end + + def test_string_inquiry + assert "production".inquiry.production? + assert !"production".inquiry.development? + end def test_truncate assert_equal "Hello World!", "Hello World!".truncate(12)