Class: String
Instance Method Summary collapse
Instance Method Details
#camelize(uppercase_first_letter = true) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/core_ext/string.rb', line 5 def camelize(uppercase_first_letter = true) string = self if uppercase_first_letter string = string.sub(/^[a-z\d]*/) { $&.capitalize } else string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } end string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::') end |
#titleize ⇒ Object
16 17 18 |
# File 'lib/core_ext/string.rb', line 16 def titleize self.split(" ").map{ |word| word.capitalize }.join(" ") end |