mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add String#inquiry as a convenience method for turning a string into a StringInquirer object [DHH]
This commit is contained in:
parent
389d15ef13
commit
39372964d2
4 changed files with 21 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
*Rails 3.1.0 (unreleased)*
|
*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]
|
* 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
|
* LocalCache strategy is now a real middleware class, not an anonymous class
|
||||||
|
|
|
@ -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/exclude'
|
||||||
require 'active_support/core_ext/string/encoding'
|
require 'active_support/core_ext/string/encoding'
|
||||||
require 'active_support/core_ext/string/strip'
|
require 'active_support/core_ext/string/strip'
|
||||||
|
require 'active_support/core_ext/string/inquiry'
|
||||||
|
|
13
activesupport/lib/active_support/core_ext/string/inquiry.rb
Normal file
13
activesupport/lib/active_support/core_ext/string/inquiry.rb
Normal file
|
@ -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
|
|
@ -250,6 +250,11 @@ class StringInflectionsTest < Test::Unit::TestCase
|
||||||
# And changes the original string:
|
# And changes the original string:
|
||||||
assert_equal original, expected
|
assert_equal original, expected
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_string_inquiry
|
||||||
|
assert "production".inquiry.production?
|
||||||
|
assert !"production".inquiry.development?
|
||||||
|
end
|
||||||
|
|
||||||
def test_truncate
|
def test_truncate
|
||||||
assert_equal "Hello World!", "Hello World!".truncate(12)
|
assert_equal "Hello World!", "Hello World!".truncate(12)
|
||||||
|
|
Loading…
Reference in a new issue