Posted By

jccovey on 06/20/08


Tagged

String camelize pluralize


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


String


 / Published in: Ruby
 

  1. class String
  2.  
  3. def camelize(word, first_letter_in_uppercase = true)
  4. if first_letter_in_uppercase
  5. word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
  6. else
  7. word.first + camelize(word)[1..-1]
  8. end
  9. end
  10.  
  11. def pluralize(num)
  12. if num == 1
  13. self
  14. else
  15. self + "s"
  16. end
  17. end
  18.  
  19. end

Report this snippet  

You need to login to post a comment.