Skip to content

Instantly share code, notes, and snippets.

@chadwickdonald
Created June 16, 2012 02:11
Show Gist options
  • Save chadwickdonald/2939632 to your computer and use it in GitHub Desktop.
Save chadwickdonald/2939632 to your computer and use it in GitHub Desktop.
a nice book
class Book
attr_reader :title
def initialize()
@title = ""
@not_cap = ["a", "and", "an", "the", "in"]
end
def title=(str)
word_array = []
first = true
str.split.each do |word|
if @not_cap.include?(word) && first == false
word_array << word
else
word_array << (word[0].upcase + word[1,word.length])
end
first = false
end
@title = word_array.join(" ")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment