-
-
Save jcsalterego/5282603 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| DONT_CAPITALIZE = %w(and or the an of in a) | |
| def title=(title) | |
| @title = title.capitalize.split.map do |word| | |
| if DONT_CAPITALIZE.include?(word.downcase) | |
| word | |
| else | |
| word.capitalize | |
| end | |
| end.join(" ").strip! | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
begin...endblock with a method, and opt for braces insteadcond ? if_true : if_false, but I opted for the plain oleif...else..end@dont_capitalizewas really a constant and thus I moved it toDONT_CAPITALIZE