Guest User

book_title01

a guest
Jun 24th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.38 KB | None | 0 0
  1. class Book
  2.   attr_reader :title
  3.  
  4.   def title=(new_book)
  5.     words = new_book.to_s.split(' ')
  6.     words.map! { |x|
  7.       if x == words[0]
  8.         x.capitalize!
  9.       elsif x == "the" || x == "and" || x == "a" || x == "an" || x == "of" || x == "in"
  10.         x = x.downcase
  11.       else
  12.         x.capitalize!
  13.         x
  14.       end
  15.     }
  16.     @title = words.join(' ')
  17.   end
  18. end
Advertisement
Add Comment
Please, Sign In to add comment