class String unless method_defined?(:camelize) def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase != :lower to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } else to_s[0].chr.downcase + camelize(self)[1..-1] end end end unless method_defined?(:camelize!) def camelize!(first_letter_in_uppercase = true) replace(camelize(first_letter_in_uppercase)) end end unless method_defined?(:ends_with?) def ends_with?(suffix) suffix = suffix.to_s self[-suffix.length, suffix.length] == suffix end end unless method_defined?(:humanize) def humanize(options = {}) underscore. gsub(/_id$/, ""). tr('_', ' '). gsub(/([a-z\d]*)/i) { |match| match.downcase }. gsub(/^\w/) { |match| match.upcase } if options.fetch(:capitalize, true) end end unless method_defined?(:humanize!) def humanize!(options = {}) replace(humanize) end end unless method_defined?(:titleize) def titleize underscore. humanize. gsub(/\b(?]*>/, "") end def strip_tags! replace(strip_tags) end def strip_whitespace gnix("\t").split(" ").remove_blanks.join(" ") end def strip_whitespace! replace(strip_whitespace) end def truncate_preserving_words(options={}) separator = options[:separator] || '...' max_words = options[:max_words] || nil if max_words words = split return self if words.size < max_words words = words[0..(max_words-1)] words << separator words.join(" ") else max_chars = options[:max_chars] || 30 return self if size < max_chars out = self[0..(max_chars-1)].split(" ") out.pop out << separator out.join(" ") end end def unpollute(delimiter="^--^--^") gsub(delimiter, "") end def upcase? upcase == self end end