Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Book
- def title()
- @title
- end
- def title=(title)
- @title=titleize(title)
- end
- def titleize(str)
- no_caps=['the','and','of','or','for','over','in','a','an']
- str_array=str.split.map do |word|
- if no_caps.include?(word)
- word.downcase
- else
- word.capitalize
- end
- end
- str_array[0].capitalize!
- title=str_array.join(" ")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment