Guest User

Untitled

a guest
May 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. # This script generates setter and getter methods for PHP.
  2.  
  3. class String
  4. def camelize
  5. result = ""
  6. self.split("_").each do |word|
  7. result += word.capitalize
  8. end
  9. result
  10. end
  11.  
  12. def lower_camelize
  13. result = ""
  14. i = 0
  15. self.split("_").each do |word|
  16. if i == 0
  17. result += word.downcase
  18. else
  19. result += word.capitalize
  20. end
  21. i += 1
  22. end
  23. result
  24. end
  25. end
  26.  
  27. %W!zip pref city town!.each do |prop|
  28. puts "
  29. /**
  30. * Setter for #{prop.camelize}
  31. *
  32. * @param
  33. * @return
  34. */
  35. public function set#{prop.camelize}($val)
  36. {
  37. $this->_#{prop.lower_camelize} = $val;
  38. return $this;
  39. }
  40.  
  41. /**
  42. * Getter for #{prop.camelize}
  43. *
  44. * @param void
  45. * @return
  46. */
  47. public function get#{prop.camelize}()
  48. {
  49. return $this->_#{prop.lower_camelize};
  50. }
  51. "
  52. end
Add Comment
Please, Sign In to add comment