Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ziya/core_ext/string.rb
Overview
Various text utils. Yes indeed lifted from Inflector.
- Author
-
Fernand Galiana
- Date
-
Dec 15th, 2006
Instance Method Summary collapse
-
#camelize_it ⇒ Object
Pulled from the Rails Inflector class and modified slightly to fit our needs.
-
#classify ⇒ Object
Pulled from the Rails Inflector class and modified slightly to fit our needs.
-
#demodulize ⇒ Object
strip out module name and return bare class name.
-
#underscore ⇒ Object
Same as Rails Inflector but eliminating inflector dependency.
Instance Method Details
#camelize_it ⇒ Object
Pulled from the Rails Inflector class and modified slightly to fit our needs.
9 10 11 |
# File 'lib/ziya/core_ext/string.rb', line 9 def camelize_it() self.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end |
#classify ⇒ Object
Pulled from the Rails Inflector class and modified slightly to fit our needs.
23 24 25 |
# File 'lib/ziya/core_ext/string.rb', line 23 def classify self.sub(/.*\./, '').camelize_it end |
#demodulize ⇒ Object
strip out module name and return bare class name
28 29 30 |
# File 'lib/ziya/core_ext/string.rb', line 28 def demodulize self.gsub( /^.*::/, '' ) end |
#underscore ⇒ Object
Same as Rails Inflector but eliminating inflector dependency
14 15 16 17 18 19 20 |
# File 'lib/ziya/core_ext/string.rb', line 14 def underscore self.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |