Class: String
Instance Method Summary collapse
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/monkey.rb', line 31 def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase != :lower self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } else self.to_s[0].chr.downcase + camelize(self)[1..-1] end end |
#underscore ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/monkey.rb', line 21 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |