Camelize (camel case) ruby string
First letter: upper
def camelize(term); term.to_s.gsub(/(?:^|_+)([^_])/) { $1.upcase } end
First letter: lower
def camelize(term)
term.to_s.gsub(/(?:^|_+)([^_])/) { $1.upcase }
.tap { |s| s[0] = s[0].downcase }
end
- See also: Underscore ruby strings
Code snippets in this post are covered by 0BSD License.