Created
April 1, 2013 00:24
-
-
Save zachgersh/5282594 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 | |
attr_reader :title | |
def title=(title) | |
@title = "" | |
@dont_capitalize = %w(and or the an of in a) | |
words = title.split | |
words.each_with_index do |word, index| | |
if @dont_capitalize.include?(word) && index != 0 | |
@title += "#{word} " | |
else | |
@title += "#{word.capitalize} " | |
end | |
end | |
@title.strip! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/jcsalterego/5282603