Free Photos
WordPress Themes

Titleize a string with exceptions

# encoding: utf-8 class String def titleize(options = {}) exclusions = options[:exclude] return ActiveSupport::Inflector.titleize(self) unless exclusions.present? self.underscore.humanize.gsub(/\b(?<!['’`])(?!#{exclusions.join('|')})[a-z]/) { $&.capitalize } end end
Extends Rails' existing `String#titleize` method to conditionally capitalize words in a sentence.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.