1
0
Fork 0
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:
David Heinemeier Hansson 2011-04-18 10:56:37 +02:00
parent 389d15ef13
commit 39372964d2
4 changed files with 21 additions and 0 deletions

View file

@ -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

View file

@ -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'

View 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

View file

@ -251,6 +251,11 @@ class StringInflectionsTest < Test::Unit::TestCase
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)
assert_equal "Hello Wor...", "Hello World!!".truncate(12)