Skip to content

Instantly share code, notes, and snippets.

@kennyt
Created October 27, 2012 09:44
Show Gist options
  • Save kennyt/3963796 to your computer and use it in GitHub Desktop.
Save kennyt/3963796 to your computer and use it in GitHub Desktop.
09_book_titles
class Book
attr_accessor :title
def title= (title)
do_not_capitalize = %w{the and a an in of}
answer = []
title.split(' ').each do |word|
do_not_capitalize.include?(word) ? word = word.downcase : word = word.capitalize
word == "i" ? word = word.capitalize : word
answer << word
end
answer[0] = answer[0].capitalize
@title = answer.join(' ')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment