Module: NobleNames::CoreExt::String
- Defined in:
- lib/noble_names/core_ext/string.rb
Instance Method Summary collapse
-
#to_title ⇒ Object
Capitalizes each Word in a name except for those which are nobility particles ‘jamie jones’.to_title # => ‘Jamie Jones’ ‘jamie of windsor’.to_title # => ‘Jamie of Windsor’.
- #to_title! ⇒ Object
Instance Method Details
#to_title ⇒ Object
Capitalizes each Word in a name except for those which are nobility particles
'jamie jones'.to_title # => 'Jamie Jones'
'jamie of windsor'.to_title # => 'Jamie of Windsor'
8 9 10 |
# File 'lib/noble_names/core_ext/string.rb', line 8 def to_title dup.to_title! end |
#to_title! ⇒ Object
12 13 14 15 16 |
# File 'lib/noble_names/core_ext/string.rb', line 12 def to_title! words = split(/\s+/) words.map! { |w| NobleNames.noble_capitalize(w) } replace(words * ' ') end |