Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/owlscribble.rb
Overview
Extensions to the built-in String class
Instance Method Summary collapse
-
#dewikiword ⇒ Object
Returns a copy of the string with spaces inserted in the ‘appropriate’ spots.
-
#dewikiword! ⇒ Object
Same as #dewikiword, but modifies the string in place.
Instance Method Details
#dewikiword ⇒ Object
Returns a copy of the string with spaces inserted in the ‘appropriate’ spots. e.g.
"WikiWord".dewikiword #-> "Wiki Word"
"OWLScribble".dewikiword #-> "OWL Scribble"
"ToXML".dewikiword #-> "To XML"
"KingOfWhales".dewikiword #-> "King of Whales"
698 699 700 |
# File 'lib/owlscribble.rb', line 698 def dewikiword self.dup.dewikiword! end |
#dewikiword! ⇒ Object
Same as #dewikiword, but modifies the string in place
703 704 705 706 707 708 |
# File 'lib/owlscribble.rb', line 703 def dewikiword! gsub! /([A-Z][a-z]+)(?=[A-Z])/, '\1 \2' gsub! /([A-Z])([A-Z][a-z])/, '\1 \2' gsub!( /\b(?:A|Am|An|And|Are|Is|Of|The|With)\b/ ){ |s| s.downcase } self end |