Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
Created June 15, 2012 01:38
Show Gist options
  • Save perspectivezoom/2934138 to your computer and use it in GitHub Desktop.
Save perspectivezoom/2934138 to your computer and use it in GitHub Desktop.
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