Skip to content

Instantly share code, notes, and snippets.

@colemanfoley
Created September 20, 2012 22:09
Show Gist options
  • Save colemanfoley/3758649 to your computer and use it in GitHub Desktop.
Save colemanfoley/3758649 to your computer and use it in GitHub Desktop.
Book class
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