Created
June 16, 2012 02:11
-
-
Save chadwickdonald/2939632 to your computer and use it in GitHub Desktop.
a nice book
This file contains 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 | |
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