Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/generators/templates/string_extensions.rb
Instance Method Summary collapse
- #capitalize_words ⇒ Object
-
#escape_filename ⇒ Object
Turns a string like “Devil’s Cave.xml” into “Devil's\ Cave.xml”, i.e.
Instance Method Details
#capitalize_words ⇒ Object
3 4 5 |
# File 'lib/generators/templates/string_extensions.rb', line 3 def capitalize_words return self.gsub(/\w+/u) { |word| word.capitalize } #gsub(/^[a-z]|\s+[a-z]/) { |a| a.upcase } end |
#escape_filename ⇒ Object
Turns a string like “Devil’s Cave.xml” into “Devil's\ Cave.xml”, i.e. escapes spaces and these: ‘&
9 10 11 |
# File 'lib/generators/templates/string_extensions.rb', line 9 def escape_filename self.split("'").join("\\'").gsub(/(\s)/, '\\\\\1').gsub("&", '\\\\&') end |