Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/extensions/string.rb
Instance Method Summary collapse
-
#pathize ⇒ Object
Transforms a namespace, i.e.
Instance Method Details
#pathize ⇒ Object
Transforms a namespace, i.e. a class or module name, into a viable file path.
"ExamplePathize".pathize #=> "example_pathize"
"ExamplePathize::Example".pathize #=> "example_pathize/example"
Compare this method to {String#modulize) and {String#methodize).
12 13 14 15 16 17 18 19 20 |
# File 'lib/extensions/string.rb', line 12 def pathize gsub(/([A-Z]+)([A-Z])/,'\1_\2'). gsub(/([a-z])([A-Z])/,'\1_\2'). gsub('__','/'). gsub('::','/'). gsub(/\s+/, ''). # spaces are bad form gsub(/[?%*:|"<>.]+/, ''). # reserved characters downcase end |