Created
June 15, 2012 01:38
-
-
Save perspectivezoom/2934138 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 = "" | |
end | |
def title=(str) | |
accum = [] | |
str.split.each_with_index do |word, indx| | |
if indx == 0 || not(%w{ the a an in and }.include? word.downcase) | |
word.capitalize! | |
else | |
word.downcase! | |
end | |
accum << word | |
end | |
@title = accum.join(" ") | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment