Module: MonkeyPatch::String::Inflectors
- Included in:
- String
- Defined in:
- ruby/trema/monkey-patch/string/inflectors.rb
Instance Method Summary collapse
Instance Method Details
#camelize ⇒ Object
22 23 24 25 26 |
# File 'ruby/trema/monkey-patch/string/inflectors.rb', line 22 def camelize self.split( /[^a-z0-9]/i ).map do | each | each.capitalize end.join end |
#demodulize ⇒ Object
29 30 31 |
# File 'ruby/trema/monkey-patch/string/inflectors.rb', line 29 def demodulize self.gsub /^.*::/, '' end |
#underscore ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'ruby/trema/monkey-patch/string/inflectors.rb', line 34 def underscore word = self.dup word.gsub! /::/, '/' word.gsub! /([A-Z]+)([A-Z][a-z])/,'\1_\2' word.gsub! /([a-z\d])([A-Z])/,'\1_\2' word.tr! "-", "_" word.downcase! word end |