Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/powertool/string.rb

Overview

Extensions to Ruby’s String class

Instance Method Summary collapse

Instance Method Details

#titleizeObject



5
6
7
8
9
10
# File 'lib/powertool/string.rb', line 5

def titleize
  # This is an alternative to the rails Tileize which removes hyphens, which
  # in all cases, including the "X Men" => "X Men" example in the rails docs.
  # See: https://apidock.com/rails/v6.1.3.1/String/titleize
  humanize.gsub(/\b('?[a-z])/) { Regexp.last_match(1).capitalize }
end