Module: NobleNames::CoreExt::String
- Defined in:
- lib/noble_names/core_ext/string.rb
Overview
This Module gives String the capability to titleize itself.
Instance Method Summary collapse
-
#to_title ⇒ String
Capitalizes each Word in a name except for those which are nobility particles.
-
#to_title! ⇒ Object
Does the same as #to_title but replaces the old string.
Instance Method Details
#to_title ⇒ String
Capitalizes each Word in a name except for those which are nobility particles
13 14 15 |
# File 'lib/noble_names/core_ext/string.rb', line 13 def to_title dup.to_title! end |
#to_title! ⇒ Object
Does the same as #to_title but replaces the old string.
22 23 24 25 26 |
# File 'lib/noble_names/core_ext/string.rb', line 22 def to_title! words = split(/\s+/) words.map! { |w| NobleNames.noble_capitalize(w) } replace(words * ' ') end |