Skip to content

Instantly share code, notes, and snippets.

@zachgersh
Created April 1, 2013 00:24
Show Gist options
  • Save zachgersh/5282594 to your computer and use it in GitHub Desktop.
Save zachgersh/5282594 to your computer and use it in GitHub Desktop.
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
@zachgersh
Copy link
Author

Based on previous feedback now doing interpolation within the Ruby convention.

@jcsalterego
Copy link

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