Skip to content

Instantly share code, notes, and snippets.

def smart_titleize
exclusion_word_pattern = /\b(and|as|at|but|by|for|from|in|into|of|on|onto|or|out|per|than|to|up|upon|via|with)\b/i
self.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
downcase.humanize.
gsub(/\b('?[a-z])/) { $1.capitalize }.
gsub(exclusion_word_pattern) { |i| i.downcase }
end