Skip to content

Instantly share code, notes, and snippets.

@jcsalterego
Forked from zachgersh/book.rb
Last active December 15, 2015 15:29
Show Gist options
  • Save jcsalterego/5282603 to your computer and use it in GitHub Desktop.
Save jcsalterego/5282603 to your computer and use it in GitHub Desktop.
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
@jcsalterego
Copy link
Author

  • Some people don't like following a begin...end block with a method, and opt for braces instead
  • Some might use the ternary operator cond ? if_true : if_false, but I opted for the plain ole if...else..end
  • @dont_capitalize was really a constant and thus I moved it to DONT_CAPITALIZE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment