Created
September 20, 2012 22:09
-
-
Save colemanfoley/3758649 to your computer and use it in GitHub Desktop.
Book class
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_accessor :title | |
def initialize | |
@title = "" | |
end | |
def title=(new_title) | |
fixed_title = "" | |
title_array = new_title.split | |
title_array.each do |word| | |
if word == "a" || word == "an" || word == "the" || word == "and" | |
fixed_title << word + " " | |
else | |
fixed_title << word.capitalize + " " | |
end | |
end | |
fixed_title[0] = fixed_title[0].upcase | |
@title = fixed_title[0..-2] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment