Permalink
Browse files

Added a #titlecase! self-modifying method as requested by Aiden Nibali.

  • Loading branch information...
1 parent d8e6a9f commit e724bf5873e800df04a4b2094b49aef7002baddd @samsouder committed Oct 16, 2009
Showing with 11 additions and 0 deletions.
  1. +4 −0 lib/titlecase.rb
  2. +7 −0 spec/titlecase_spec.rb
View
4 lib/titlecase.rb
@@ -15,6 +15,10 @@ def titlecase
x.join(" ").gsub(/:\s?(\W*#{small_words.join("|")}\W*)\s/) { ": #{$1.smart_capitalize} " }
end
+ def titlecase!
+ replace(titlecase)
+ end
+
def smart_capitalize
# ignore any leading crazy characters and capitalize the first real character
if self =~ /^['"\(\[']*([a-z])/
View
7 spec/titlecase_spec.rb
@@ -10,4 +10,11 @@
end
end
end
+
+ # Ensure the self-modifying version works correctly
+ it "should self-modify the original value in place" do
+ string = 'a complex thing'
+ string.titlecase!
+ string.should == 'A Complex Thing'
+ end
end

0 comments on commit e724bf5

Please sign in to comment.