Created
January 21, 2013 17:33
-
-
Save andyjbas/4587688 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book | |
def initialize | |
end | |
attr_reader :title | |
def title=(string) | |
@title = string.titlize | |
end | |
end | |
class String | |
def titlize | |
array = self.split | |
array[1..-1].collect! { |s| s.selective_caps } | |
array.first.capitalize! | |
array.join(" ") | |
end | |
def selective_caps | |
small_words = %w(a an and as at but by en for if in of on or the to v v. via vs vs.) | |
return self if small_words.include?(self) | |
self.capitalize! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment